Advanced Excel Chapter 12: Essential DAX Functions - Tutorial Rays
Advanced Excel

Advanced Excel Chapter 12: Essential DAX Functions

Essential DAX Functions and Measures with Practical Examples

DAX stands for Data Analysis Expressions. It is a formula language used to create calculations in Power Pivot, Excel Data Models, Power BI and Analysis Services.

DAX formulas may look similar to Excel formulas, but they work with tables, columns, relationships and filter context. A single DAX measure can calculate different results automatically for each product, region, customer, month or slicer selection.

In this chapter, you will learn how to create calculated columns and measures using SUM, SUMX, COUNTROWS, DISTINCTCOUNT, DIVIDE, RELATED, CALCULATE, FILTER, ALL and essential time-intelligence functions.

Learning Objectives

After completing this chapter, you should be able to:

  • Understand the purpose of DAX.
  • Differentiate calculated columns and measures.
  • Understand row context and filter context.
  • Create basic aggregation measures.
  • Use iterator functions such as SUMX.
  • Retrieve values from related tables.
  • Modify filter context using CALCULATE.
  • Create filtered calculations using FILTER.
  • Calculate percentages of totals.
  • Create distinct counts and average values.
  • Create month-to-date and year-to-date calculations.
  • Build reusable business KPIs.

1. What Is DAX?

DAX is a collection of functions, operators and constants used to build formulas in a relational Data Model.

DAX Can Be Used To Create:

  • Calculated columns
  • Measures
  • Calculated tables in supported tools
  • Sales and profit KPIs
  • Percentages of totals
  • Rankings
  • Running totals
  • Year-to-date calculations
  • Period comparisons
  • Customer and product analysis

2. DAX vs Excel Worksheet Formulas

Excel worksheet formulas DAX formulas
Usually reference cells and ranges Reference tables and columns
Example: =SUM(B2:B100) Example: SUM(FactSales[SalesAmount])
Calculated inside worksheets Calculated inside the Data Model
Often copied down rows Measures are reused across reports
Controlled mainly by cell references Controlled by row and filter context

3. Create the Required Data Model

Use the star-schema model created in Chapter 11.


                 DimDate
                    |
                    |
DimCustomer —— FactSales —— DimProduct
                    |
                    |
             DimSalesperson
                    |
                    |
                DimRegion

FactSales Columns

  • OrderID
  • OrderDate
  • ProductID
  • CustomerID
  • SalespersonID
  • RegionID
  • Quantity
  • UnitPrice
  • SalesAmount
  • CostAmount
  • Status

Dimension Tables

  • DimProduct
  • DimCustomer
  • DimSalesperson
  • DimRegion
  • DimDate

4. Understanding DAX Syntax

Column Reference

FactSales[SalesAmount]

Measure Reference

[Total Sales]

Table Reference

FactSales

Table Name Containing Spaces

'Sales Transactions'[Sales Amount]

Basic Measure Structure

Measure Name :=
DAX Expression

Example

Total Sales :=
SUM(FactSales[SalesAmount])

Depending on the Excel locale, DAX may use semicolons instead of commas as argument separators.

5. Calculated Columns

A calculated column evaluates a formula for every row and stores the results inside the Data Model.

Calculate Sales Amount

Line Sales =
FactSales[Quantity] * FactSales[UnitPrice]

Calculate Profit per Transaction

Line Profit =
FactSales[SalesAmount] - FactSales[CostAmount]

Classify Orders

Sales Category =
IF(
    FactSales[SalesAmount] >= 100000,
    "High Value",
    IF(
        FactSales[SalesAmount] >= 50000,
        "Medium Value",
        "Regular"
    )
)

When to Use a Calculated Column

  • Creating a row-level category
  • Creating a technical key
  • Creating a value used in a slicer or hierarchy
  • Retrieving a related dimension value
  • Creating a row-level classification

6. Measures

A measure calculates a result according to the current report filters. It is not calculated and stored separately for every transaction row.

Total Sales Measure

Total Sales :=
SUM(FactSales[SalesAmount])

How the Measure Responds

  • In a Product row, it calculates that product’s sales.
  • In a Region row, it calculates that region’s sales.
  • In a Year row, it calculates that year’s sales.
  • In the Grand Total, it calculates total sales.
  • When a slicer changes, the result recalculates.

7. Calculated Column vs Measure

Calculated column Measure
Evaluated row by row Evaluated in filter context
Result stored in the model Calculated when requested
Can be used in Rows and Columns Normally used in Values
May increase model size Usually more efficient for KPIs
Example: Sales Category Example: Total Sales

8. Creating a Measure in Power Pivot

  1. Go to Power Pivot → Manage.
  2. Select the FactSales table.
  3. Display the Calculation Area.
  4. Select an empty cell in the Calculation Area.
  5. Enter the DAX measure.
  6. Press Enter.
  7. Apply the appropriate number format.

Alternative Method

Use Power Pivot → Measures → New Measure from the Excel Ribbon.

9. Basic Aggregation Measures

Total Sales

Total Sales :=
SUM(FactSales[SalesAmount])

Total Cost

Total Cost :=
SUM(FactSales[CostAmount])

Total Quantity

Total Quantity :=
SUM(FactSales[Quantity])

Average Sale

Average Sale :=
AVERAGE(FactSales[SalesAmount])

Highest Sale

Highest Sale :=
MAX(FactSales[SalesAmount])

Lowest Sale

Lowest Sale :=
MIN(FactSales[SalesAmount])

10. Counting Records with COUNTROWS

COUNTROWS counts the number of rows in a table or table expression.

Count Transaction Rows

Transaction Count :=
COUNTROWS(FactSales)

Count Completed Transactions

Completed Transactions :=
CALCULATE(
    COUNTROWS(FactSales),
    FactSales[Status] = "Completed"
)

Count Cancelled Transactions

Cancelled Transactions :=
CALCULATE(
    COUNTROWS(FactSales),
    FactSales[Status] = "Cancelled"
)

11. Counting Unique Values with DISTINCTCOUNT

DISTINCTCOUNT counts the number of different values in a column.

Unique Orders

Order Count :=
DISTINCTCOUNT(FactSales[OrderID])

Unique Customers

Customer Count :=
DISTINCTCOUNT(FactSales[CustomerID])

Unique Products Sold

Products Sold :=
DISTINCTCOUNT(FactSales[ProductID])

COUNTROWS vs DISTINCTCOUNT

COUNTROWS DISTINCTCOUNT
Counts transaction rows Counts unique column values
Duplicate IDs are counted repeatedly Duplicate IDs are counted once
Useful for line-item count Useful for unique orders or customers

12. Creating Arithmetic Measures

Total Profit

Total Profit :=
[Total Sales] - [Total Cost]

Average Order Value

Average Order Value :=
DIVIDE(
    [Total Sales],
    [Order Count],
    0
)

Average Units per Order

Average Units per Order :=
DIVIDE(
    [Total Quantity],
    [Order Count],
    0
)

13. Using the DIVIDE Function

DIVIDE performs division and provides an alternate result when the denominator is zero or blank.

DIVIDE Syntax

DIVIDE(numerator,denominator,[alternate_result])

Profit Margin Percentage

Profit Margin % :=
DIVIDE(
    [Total Profit],
    [Total Sales],
    0
)

Completion Rate

Completion Rate % :=
DIVIDE(
    [Completed Transactions],
    [Transaction Count],
    0
)

Format these measures as percentages.

14. Understanding Row Context

Row context means that DAX is evaluating one current row. Calculated columns naturally have row context.

Example

Line Profit =
FactSales[SalesAmount] - FactSales[CostAmount]

For every FactSales row, DAX uses SalesAmount and CostAmount from that current row.

Row Context Is Commonly Created By:

  • Calculated columns
  • Iterator functions such as SUMX
  • FILTER
  • AVERAGEX
  • MINX and MAXX

15. Understanding Filter Context

Filter context is the collection of filters affecting a measure when it is evaluated.

Filters Can Come From:

  • PivotTable rows
  • PivotTable columns
  • Report filters
  • Slicers
  • Timelines
  • Relationships
  • CALCULATE

Example

Total Sales :=
SUM(FactSales[SalesAmount])

If a PivotTable row contains East, the measure calculates East sales. If it contains Laptop, the measure calculates Laptop sales. The formula remains unchanged; the filter context changes.

16. Row Context vs Filter Context

Row context Filter context
Represents the current row Represents active filters
Common in calculated columns Common in measures
Created by iterators Created by reports and CALCULATE
Does not automatically filter every related calculation Propagates through model relationships

17. Using the SUMX Function

SUMX is an iterator. It evaluates an expression for every row in a table and then adds the results.

SUMX Syntax

SUMX(table,expression)

Calculate Sales from Quantity and Unit Price

Calculated Sales :=
SUMX(
    FactSales,
    FactSales[Quantity] * FactSales[UnitPrice]
)

How SUMX Works


Row 1: Quantity × Unit Price
Row 2: Quantity × Unit Price
Row 3: Quantity × Unit Price
        ↓
Add every row result
        ↓
Calculated Sales

Calculate Profit with SUMX

Calculated Profit :=
SUMX(
    FactSales,
    FactSales[SalesAmount] - FactSales[CostAmount]
)

18. SUM vs SUMX

SUM SUMX
Adds one numerical column Evaluates an expression row by row
SUM(FactSales[SalesAmount]) SUMX(FactSales,Quantity * Price)
Usually faster for a stored column Used when row-level calculation is required

19. Using AVERAGEX

AVERAGEX evaluates an expression for each row and calculates the average of those results.

Average Calculated Line Value

Average Line Value :=
AVERAGEX(
    FactSales,
    FactSales[Quantity] * FactSales[UnitPrice]
)

Average Product Profit

Average Line Profit :=
AVERAGEX(
    FactSales,
    FactSales[SalesAmount] - FactSales[CostAmount]
)

20. Using RELATED

RELATED retrieves one related value from another table. A valid relationship must exist, and the formula requires row context.

Retrieve Product Category into FactSales

Product Category =
RELATED(DimProduct[Category])

Retrieve Product Name

Product Name =
RELATED(DimProduct[ProductName])

Retrieve Customer State

Customer State =
RELATED(DimCustomer[State])

Retrieve Salesperson Name

Salesperson Name =
RELATED(DimSalesperson[SalespersonName])

Requirements for RELATED

  • A relationship must exist.
  • The related table must provide one matching value.
  • The current calculation must have row context.
  • The key data types must be compatible.

21. Using RELATED inside SUMX

Suppose Standard Cost is stored in DimProduct rather than FactSales.

Calculate Total Standard Cost

Total Standard Cost :=
SUMX(
    FactSales,
    FactSales[Quantity] *
    RELATED(DimProduct[StandardCost])
)

Calculate Profit Using Related Cost

Profit from Standard Cost :=
[Calculated Sales] - [Total Standard Cost]

22. Using CALCULATE

CALCULATE evaluates an expression in a modified filter context. It is one of the most important functions in DAX.

CALCULATE Syntax

CALCULATE(
    expression,
    filter1,
    filter2
)

Completed Sales

Completed Sales :=
CALCULATE(
    [Total Sales],
    FactSales[Status] = "Completed"
)

Cancelled Sales

Cancelled Sales :=
CALCULATE(
    [Total Sales],
    FactSales[Status] = "Cancelled"
)

Laptop Sales

Laptop Sales :=
CALCULATE(
    [Total Sales],
    DimProduct[ProductName] = "Laptop"
)

East Region Sales

East Sales :=
CALCULATE(
    [Total Sales],
    DimRegion[RegionName] = "East"
)

23. CALCULATE with Multiple Conditions

Completed Computer Sales in the East Region

East Completed Computer Sales :=
CALCULATE(
    [Total Sales],
    DimRegion[RegionName] = "East",
    DimProduct[Category] = "Computer",
    FactSales[Status] = "Completed"
)

Separate CALCULATE filter arguments generally work together using AND logic.

Sales for One Selected Year

Sales 2026 :=
CALCULATE(
    [Total Sales],
    DimDate[Year] = 2026
)

24. Using the FILTER Function

FILTER evaluates a condition row by row and returns a filtered table. It is often used inside CALCULATE or an iterator.

FILTER Syntax

FILTER(table,condition)

Sales from High-Value Transactions

High Value Sales :=
CALCULATE(
    [Total Sales],
    FILTER(
        FactSales,
        FactSales[SalesAmount] >= 100000
    )
)

Count High-Value Transactions

High Value Transaction Count :=
COUNTROWS(
    FILTER(
        FactSales,
        FactSales[SalesAmount] >= 100000
    )
)

Profitable Sales Transactions

Profitable Sales :=
CALCULATE(
    [Total Sales],
    FILTER(
        FactSales,
        FactSales[SalesAmount] >
        FactSales[CostAmount]
    )
)

25. Boolean Filters vs FILTER

Simple Boolean Filter

Completed Sales :=
CALCULATE(
    [Total Sales],
    FactSales[Status] = "Completed"
)

Table Filter

High Margin Sales :=
CALCULATE(
    [Total Sales],
    FILTER(
        FactSales,
        DIVIDE(
            FactSales[SalesAmount] -
            FactSales[CostAmount],
            FactSales[SalesAmount],
            0
        ) >= 20%
    )
)

Use simple Boolean filters where possible. Use FILTER when the condition requires a row-by-row expression or more complex table logic.

26. Using ALL

ALL returns all rows or values from a table or column while ignoring selected filters on that table or column.

Sales Ignoring Product Filters

All Product Sales :=
CALCULATE(
    [Total Sales],
    ALL(DimProduct)
)

Sales Ignoring Region Filters

All Region Sales :=
CALCULATE(
    [Total Sales],
    ALL(DimRegion)
)

Grand Total Sales

Grand Total Sales :=
CALCULATE(
    [Total Sales],
    ALL(FactSales)
)

Removing every FactSales filter may also remove filters propagated to it. Select the table or column carefully according to the required business result.

27. Calculate Percentage of Total

Product Sales Percentage

Product Sales % :=
DIVIDE(
    [Total Sales],
    CALCULATE(
        [Total Sales],
        ALL(DimProduct)
    ),
    0
)

Region Sales Percentage

Region Sales % :=
DIVIDE(
    [Total Sales],
    CALCULATE(
        [Total Sales],
        ALL(DimRegion)
    ),
    0
)

Format the measures as percentages.

28. Using REMOVEFILTERS

REMOVEFILTERS explicitly removes filters from selected tables or columns where supported.

Sales Percentage of All Products

Product Contribution % :=
DIVIDE(
    [Total Sales],
    CALCULATE(
        [Total Sales],
        REMOVEFILTERS(DimProduct)
    ),
    0
)

ALL can return a table and can also act as a filter modifier. REMOVEFILTERS communicates the filter-removal intention more clearly where available.

29. Using ALLEXCEPT

ALLEXCEPT removes filters from a table except filters applied to selected columns.

Keep Year but Remove Other Date Filters

Annual Sales :=
CALCULATE(
    [Total Sales],
    ALLEXCEPT(
        DimDate,
        DimDate[Year]
    )
)

The measure keeps the Year filter but removes filters from other DimDate columns.

30. Understanding Context Transition

CALCULATE can convert row context into filter context. This process is known as context transition.

Example Scenario

A calculated column in DimCustomer may need to calculate total sales for the current customer.

Customer Sales =
CALCULATE(
    SUM(FactSales[SalesAmount])
)

CALCULATE turns the current DimCustomer row into a filter that affects related FactSales records.

When an existing model measure is evaluated inside row context, context transition can occur automatically.

31. Create Customer KPI Measures

Customer Count

Customer Count :=
DISTINCTCOUNT(FactSales[CustomerID])

Sales per Customer

Sales per Customer :=
DIVIDE(
    [Total Sales],
    [Customer Count],
    0
)

Customers with Sales

Active Customer Count :=
COUNTROWS(
    FILTER(
        VALUES(DimCustomer[CustomerID]),
        [Total Sales] > 0
    )
)

32. Create Product KPI Measures

Product Count

Product Count :=
DISTINCTCOUNT(FactSales[ProductID])

Sales per Product

Sales per Product :=
DIVIDE(
    [Total Sales],
    [Product Count],
    0
)

Products with Sales Above ₹100,000

High Performing Products :=
COUNTROWS(
    FILTER(
        VALUES(DimProduct[ProductID]),
        [Total Sales] >= 100000
    )
)

33. Using VALUES

VALUES returns the distinct values visible in the current filter context.

Count Visible Products

Visible Product Count :=
COUNTROWS(
    VALUES(DimProduct[ProductID])
)

Use with an Iterator

Average Sales per Visible Product :=
AVERAGEX(
    VALUES(DimProduct[ProductID]),
    [Total Sales]
)

34. Create a Calendar Table for Time Intelligence

Time-intelligence calculations require a reliable Calendar table containing a continuous date sequence.

Required Calendar Fields

  • Date
  • Year
  • Quarter
  • Month Number
  • Month Name
  • Month-Year

Required Relationship

DimDate[Date]
      1
      ↓
      Many
FactSales[OrderDate]

Calendar Requirements

  • One row for every date
  • No missing dates
  • No duplicate dates
  • No blank dates
  • Covers the complete transaction period
  • Uses a valid date data type

35. Mark the Calendar as a Date Table

  1. Open Power Pivot.
  2. Select the DimDate table.
  3. Select Design → Mark as Date Table.
  4. Select the Date column.
  5. Click OK.

The available command may differ by Excel version, but the model should always contain a proper Calendar table and relationship.

36. Month-to-Date Sales

Sales MTD :=
TOTALMTD(
    [Total Sales],
    DimDate[Date]
)

This measure calculates sales from the beginning of the current month to the latest visible date.

37. Quarter-to-Date Sales

Sales QTD :=
TOTALQTD(
    [Total Sales],
    DimDate[Date]
)

38. Year-to-Date Sales

Sales YTD :=
TOTALYTD(
    [Total Sales],
    DimDate[Date]
)

Financial Year Ending 31 March

Sales Financial YTD :=
TOTALYTD(
    [Total Sales],
    DimDate[Date],
    ,
    "3/31"
)

The year-end date string can depend on the workbook locale. Test fiscal-year calculations carefully.

39. Previous-Year Sales

Sales Previous Year :=
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR(
        DimDate[Date]
    )
)

Year-over-Year Difference

YoY Sales Change :=
[Total Sales] - [Sales Previous Year]

Year-over-Year Percentage

YoY Sales Change % :=
DIVIDE(
    [Total Sales] - [Sales Previous Year],
    [Sales Previous Year],
    0
)

40. Previous-Month Sales

Sales Previous Month :=
CALCULATE(
    [Total Sales],
    DATEADD(
        DimDate[Date],
        -1,
        MONTH
    )
)

Month-over-Month Difference

MoM Sales Change :=
[Total Sales] - [Sales Previous Month]

Month-over-Month Percentage

MoM Sales Change % :=
DIVIDE(
    [Total Sales] - [Sales Previous Month],
    [Sales Previous Month],
    0
)

41. Running Total Sales

Running Total Sales :=
CALCULATE(
    [Total Sales],
    FILTER(
        ALL(DimDate[Date]),
        DimDate[Date] <=
        MAX(DimDate[Date])
    )
)

How the Running Total Works

  • ALL removes the current individual date filter.
  • MAX finds the latest visible date.
  • FILTER keeps every date up to that date.
  • CALCULATE evaluates Total Sales across those dates.

42. Rolling 30-Day Sales

Rolling 30 Day Sales :=
CALCULATE(
    [Total Sales],
    DATESINPERIOD(
        DimDate[Date],
        MAX(DimDate[Date]),
        -30,
        DAY
    )
)

43. Sales Target Measures

Suppose a Sales Target measure or related target table provides the applicable target.

Example Fixed Target

Sales Target :=
1000000

Target Achievement

Target Achievement % :=
DIVIDE(
    [Total Sales],
    [Sales Target],
    0
)

Target Variance

Target Variance :=
[Total Sales] - [Sales Target]

Target Status

Target Status :=
IF(
    [Total Sales] >= [Sales Target],
    "Achieved",
    "Not Achieved"
)

44. Creating KPI Status Measures

Profit Status

Profit Status :=
SWITCH(
    TRUE(),
    [Profit Margin %] >= 25%, "Excellent",
    [Profit Margin %] >= 15%, "Good",
    [Profit Margin %] >= 5%, "Low",
    "Loss or Critical"
)

Sales Growth Status

Growth Status :=
SWITCH(
    TRUE(),
    [YoY Sales Change %] > 0, "Growth",
    [YoY Sales Change %] = 0, "No Change",
    "Decline"
)

45. Ranking with RANKX

Rank Products by Sales

Product Sales Rank :=
RANKX(
    ALL(DimProduct[ProductName]),
    [Total Sales],
    ,
    DESC,
    DENSE
)

Rank Salespeople

Salesperson Rank :=
RANKX(
    ALL(DimSalesperson[SalespersonName]),
    [Total Sales],
    ,
    DESC,
    DENSE
)

Show Only the Top Five Products

Add Product Sales Rank to the PivotTable and filter it to values less than or equal to 5.

46. Using Variables

Variables make complex measures easier to read, test and maintain.

Profit Margin with Variables

Profit Margin with Variables :=
VAR SalesValue = [Total Sales]
VAR ProfitValue = [Total Profit]
RETURN
    DIVIDE(
        ProfitValue,
        SalesValue,
        0
    )

Year-over-Year Growth with Variables

YoY Growth % :=
VAR CurrentSales = [Total Sales]
VAR PreviousSales = [Sales Previous Year]
VAR Difference = CurrentSales - PreviousSales
RETURN
    DIVIDE(
        Difference,
        PreviousSales,
        0
    )

47. Formatting Measures

Currency Measures

  • Total Sales
  • Total Cost
  • Total Profit
  • Average Order Value

Percentage Measures

  • Profit Margin %
  • Completion Rate %
  • Product Contribution %
  • Target Achievement %
  • YoY Sales Change %

Whole-Number Measures

  • Order Count
  • Customer Count
  • Product Count
  • Transaction Count

Set the measure format in Power Pivot instead of manually reformatting every PivotTable.

48. Organizing Measures

Recommended Measure Groups

  • Sales Measures
  • Profit Measures
  • Customer Measures
  • Order Measures
  • Time-Intelligence Measures
  • Target Measures

Recommended Naming


Total Sales
Total Profit
Profit Margin %
Order Count
Average Order Value
Sales YTD
Sales Previous Year
YoY Sales Change %

Use business-friendly names and avoid names such as Measure1 or Calculation2.

49. Common DAX Mistakes

  • Creating calculated columns when a measure is more suitable
  • Confusing row context with filter context
  • Using SUM when a row-level expression requires SUMX
  • Using normal division instead of DIVIDE
  • Creating time calculations without a proper Calendar table
  • Using RELATED without a valid relationship
  • Removing too many filters with ALL
  • Writing FILTER for simple conditions unnecessarily
  • Using transaction-table text columns for every slicer
  • Failing to validate totals against the source
  • Creating long formulas without variables
  • Failing to format measures properly

50. DAX Best Practices

  • Build a clean star-schema Data Model first.
  • Create explicit measures for important KPIs.
  • Use measures instead of unnecessary calculated columns.
  • Use SUM for stored numerical columns.
  • Use SUMX for row-level expressions.
  • Use DIVIDE for safe division.
  • Use dimension columns for filtering.
  • Use CALCULATE carefully to modify context.
  • Use simple Boolean filters when possible.
  • Create and relate a complete Calendar table.
  • Use variables in complex calculations.
  • Apply meaningful measure names and formats.
  • Test measures at detail and grand-total levels.

51. Practical Assignment: DAX Sales Performance Dashboard

Create a Power Pivot dashboard using the multi-table sales model from Chapter 11.

Required Base Measures

  1. Total Sales
  2. Total Cost
  3. Total Profit
  4. Profit Margin %
  5. Total Quantity
  6. Order Count
  7. Customer Count
  8. Product Count
  9. Average Order Value

Required Conditional Measures

  1. Completed Sales
  2. Cancelled Sales
  3. High-Value Sales
  4. East Region Sales
  5. Computer Category Sales
  6. Completion Rate %

Required Time Measures

  1. Sales MTD
  2. Sales QTD
  3. Sales YTD
  4. Sales Previous Month
  5. Sales Previous Year
  6. MoM Sales Change %
  7. YoY Sales Change %
  8. Running Total Sales
  9. Rolling 30-Day Sales

Required Ranking and Target Measures

  1. Product Sales Rank
  2. Salesperson Rank
  3. Sales Target
  4. Target Achievement %
  5. Target Variance
  6. Target Status

Dashboard Requirements

  • Total Sales KPI card
  • Total Profit KPI card
  • Profit Margin KPI card
  • Order Count KPI card
  • Monthly Sales Trend
  • Current vs Previous Year chart
  • Top Five Products chart
  • Salesperson ranking table
  • Region and Product slicers
  • Year and Month filters

52. Practice Exercises

Exercise 1: Customer Analysis

Create Customer Count, Sales per Customer, Customer Sales Rank and Customer Contribution Percentage measures.

Exercise 2: Product Profitability

Create Total Product Sales, Total Product Cost, Product Profit, Profit Margin and Product Rank measures.

Exercise 3: Order Status Analysis

Calculate Completed, Pending and Cancelled transaction counts and their percentages of total transactions.

Exercise 4: Time Analysis

Create MTD, QTD, YTD, previous-month, previous-year and running-total measures.

Exercise 5: Regional Performance

Calculate Total Sales, Profit, Sales Contribution and Rank for each region.

53. Chapter Quiz

  1. What does DAX stand for?
  2. What is the difference between a calculated column and a measure?
  3. What is row context?
  4. What is filter context?
  5. What is the difference between SUM and SUMX?
  6. What does RELATED require?
  7. What is the primary purpose of CALCULATE?
  8. What does FILTER return?
  9. Why should DIVIDE be used?
  10. What does DISTINCTCOUNT calculate?
  11. Why is a Calendar table required?
  12. What does TOTALYTD calculate?

54. Frequently Asked Questions

Is DAX the same as an Excel formula?

No. Some functions look similar, but DAX operates on Data Model tables, columns, relationships and filter context instead of ordinary worksheet cells.

Should I create a measure or calculated column?

Use a calculated column for necessary row-level values and categories. Use a measure for totals, averages, percentages and KPIs that should respond to filters.

Why does the same measure show different values in different PivotTable rows?

Each row creates a different filter context. The measure recalculates for the current Product, Region, Customer or Date selection.

When should SUMX be used instead of SUM?

Use SUM for an existing numerical column. Use SUMX when an expression must be evaluated separately for every row before the results are added.

Why does RELATED return an error?

The relationship may be missing or invalid, the key data types may differ, or the formula may not have row context.

Why is my time-intelligence measure incorrect?

Check that DimDate contains continuous, unique dates, covers the full transaction period and has an active relationship with the fact-table date.

Official References

Conclusion

DAX converts an Excel Data Model into a reusable analytical system. Basic functions such as SUM, COUNTROWS and DISTINCTCOUNT calculate totals and counts, while iterator functions such as SUMX evaluate row-level expressions.

CALCULATE modifies filter context, FILTER creates filtered tables and RELATED retrieves values through model relationships. A proper Calendar table enables month-to-date, year-to-date, previous-period and running-total calculations.

In the next chapter, we will study Excel charts and data visualization, including chart selection, professional formatting, combo charts, waterfall charts, histograms, Pareto charts, sparklines and dynamic chart titles.

Leave a Reply

Your email address will not be published. Required fields are marked *