Power BI Exercise - Creating Basic DAX Measures (Retail Dataset)

Power BI Exercise - Creating Basic DAX Measures (Retail Dataset)

Create reusable calculations for sales, quantity, transaction count, and average sale value.

Exercise objectives

  • Understand the purpose of a DAX measure.
  • Create four basic measures using SUM, DISTINCTCOUNT, and DIVIDE.
  • Format currency and numeric measures correctly.
  • Display the measures using card visuals.
  • Test how the measures respond to Region and Channel filters.

Introduction to DAX

DAX stands for Data Analysis Expressions. It is the formula language used by Power BI to create calculations from data that has already been loaded into the model.

DAX may look similar to an Excel formula, but it works with tables, columns, relationships, and report filters. In this exercise, DAX will be used to create measures.

What is a measure?

A measure is a named calculation that Power BI evaluates when it is needed. Its result can change when a user selects a slicer, applies a filter, or views a different category.

For example, the same Total Sales measure can return:

  • RM21,788 when no filter is applied.
  • RM9,281 when Region is filtered to Central.
  • RM6,545 when Channel is filtered to Online.
Important: A measure does not store one permanent result inside the table. Power BI recalculates it according to the current filter context.

Basic structure of a DAX measure

Total Sales =
SUM ( Sales[SalesAmount] )
Formula partExampleMeaning
Measure nameTotal SalesThe name displayed in the Data pane
Equals sign=Separates the measure name from its calculation
DAX functionSUMAdds the values in a numeric column
Table nameSalesThe table containing the required column
Column name[SalesAmount]The column whose values will be added

DAX functions used in this exercise

FunctionPurposeExample use
SUMAdds all visible values in a numeric columnTotal sales and total quantity
DISTINCTCOUNTCounts unique valuesNumber of SaleID transactions
DIVIDEDivides two values and safely handles a zero denominatorAverage sale value

Measure compared with a calculated column

MeasureCalculated column
Produces a result when used in a query, visual, or filterProduces and stores a value for every table row
Responds to report filter contextCalculated row by row during data refresh
Best for totals, averages, ratios, and KPIsBest for row-level labels, categories, and values needed for relationships
Shown with a calculator iconShown as a regular column field
Key idea: Columns provide the data, while measures answer questions about that data.

Before you begin

This exercise continues from the retail dataset exercise. Your Power BI file should contain a table named Sales with 15 rows and the following columns:

Required columnsControl value
SaleID, SaleDate, Product, Category, Region, Channel, Quantity, UnitPrice, SalesAmount15 rows
SalesAmountRM21,788 total

Step 1: Create the Total Sales measure

  1. In the Data pane, select the Sales table.
  2. On the ribbon, select Modeling → New measure.
  3. Replace the default formula with the DAX below.
  4. Press Enter.
Total Sales =
SUM ( Sales[SalesAmount] )

Format the measure

  1. Select Total Sales in the Data pane.
  2. Open Measure tools.
  3. Set the format to Currency.
  4. Select Malaysian Ringgit or enter RM as the currency symbol.
  5. Set decimal places to 0.

View the result without adding a visual

  1. Select the DAX Query View icon on the left side of Power BI Desktop.
  2. In the Data pane, expand the Sales table.
  3. Right-click the Total Sales measure.
  4. Select Quick queries → Evaluate.
  5. Power BI creates and runs a query similar to the following:
EVALUATE
    SUMMARIZECOLUMNS(
        "Total Sales", [Total Sales]
    )
  1. If the query does not run automatically, select Run.
  2. Look at the Results grid below the query editor.
  3. Confirm that Total Sales returns 21788.
Formatting note: DAX Query View can display the raw value 21788 instead of the formatted value RM21,788. Both represent the same measure result.
Expected result: Total Sales = RM21,788.

Step 2: Create the Total Quantity measure

Create another measure in the Sales table:

Total Quantity =
SUM ( Sales[Quantity] )

Format this measure as a whole number with no decimal places.

Expected result: Total Quantity = 42.

Step 3: Create the Transaction Count measure

Each transaction has a unique SaleID. Use DISTINCTCOUNT so that each SaleID is counted only once.

Transaction Count =
DISTINCTCOUNT ( Sales[SaleID] )

Format this measure as a whole number.

Expected result: Transaction Count = 15.

Step 4: Create the Average Sale Value measure

Calculate the average value of one transaction by dividing Total Sales by Transaction Count.

Average Sale Value =
DIVIDE ( [Total Sales], [Transaction Count] )

Format this measure as currency with two decimal places.

Why use DIVIDE? DIVIDE safely handles a zero or blank denominator. This is generally preferable to using the division operator for report measures.
Expected result: Average Sale Value = RM1,452.53.

Verify the four measures

RM21,788Total Sales
42Total Quantity
15Transaction Count
RM1,452.53Average Sale Value

Step 5: Create card visuals

  1. Open Report view.
  2. Select the Card visual.
  3. Drag Total Sales into the card.
  4. Create three more cards for Total Quantity, Transaction Count, and Average Sale Value.
  5. Arrange the four cards in one row.
  6. Give each card a clear title and check its number format.

Step 6: Test filter context

  1. Add a Slicer visual.
  2. Add Region to the slicer.
  3. Add a second slicer using Channel.
  4. Select different values and confirm that all four cards change.
  5. Clear both slicers to restore the full-dataset results.

Filter checkpoints

FilterTotal SalesTotal QuantityTransaction CountAverage Sale Value
No filterRM21,7884215RM1,452.53
Region = CentralRM9,28195RM1,856.20
Channel = OnlineRM6,545257RM935.00
Channel = StoreRM15,243178RM1,905.38

Troubleshooting

ProblemLikely causeCorrection
The formula cannot find SalesThe imported table has another nameRename the table to Sales or use its current name in the formula
Total Sales is incorrectSalesAmount has the wrong data typeSet SalesAmount to Fixed decimal number
Transaction Count is 42Quantity was counted instead of SaleIDUse DISTINCTCOUNT on Sales[SaleID]
Average Sale Value produces an errorThe measure names do not matchUse the exact names Total Sales and Transaction Count
Cards do not respond to a slicerVisual interaction may be disabledUse Edit interactions and enable filtering for each card

Completion checklist

  • Four measures have been created in the Sales table.
  • Currency and whole-number formats are correct.
  • Four card visuals show the expected unfiltered results.
  • Region and Channel slicers update all four cards.
  • The filter checkpoint results match the values shown above.
Exercise complete: You have created reusable DAX measures and confirmed that they respond correctly to filter context.