Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Ilgar_Zarbali

Working with X-Functions in DAX (SUMX, AVERAGEX, etc.)

Our sales data is in Azerbaijani Manat, but we also want to display it in USD. To achieve this, we add a calculated column to the fSales table:

Sales in USD = fSales[Amount] / RELATED('DCurrency(F)'[EUR/USD])

1.png

 

Now, we can visualize sales data in both Euros and USD by store. However, using X-functions (iterators) allows us to perform the same calculation virtually, eliminating the need for calculated columns.

 

2.png

Let’s replicate the functionality of the calculated column using the SUMX function:

 

Sales USD = SUMX(fSales, fSales[Amount] / RELATED('DCurrency(F)'[EUR/USD]))

 Adding this measure to a table yields the same results as the calculated column. Once confirmed, we can delete the calculated column.

 

3.png

 

Here’s another example: calculating the average check amount. In the fSales table, there’s a column for cash slips. Each cash slip can have multiple rows, so taking a simple average of the Amount column won’t work. First, we need to aggregate the table by cash slip number, then calculate the average.

Using the SUMMARIZE function, we can create an aggregated table:

Average Slip= SUMMARIZE(fSales, fSales[Cash Slip Number])

4.png

 

This gives us a list of unique cash slip numbers. To calculate the total amount for each slip, we can use the ADDCOLUMNS function:

Table = ADDCOLUMNS(
    SUMMARIZE(fSales, fSales[Cash Slip Number]),
    "Slip Amount",
    CALCULATE(SUM(fSales[Amount]))
)

We can now use this table to display the data. Replacing SUM with AVERAGE will give the average check amount. However, since this table is not dynamically linked to the model, it has some limitations. The results are static and cannot adapt to slicers or filters.

5.png

To make this dynamic, we use the AVERAGEX function:

 

Average Slip = AVERAGEX(
    ADDCOLUMNS(
        SUMMARIZE(fSales, fSales[Cash Slip Number]),
        "Slip Amount",
        CALCULATE(SUM(fSales[Amount]))
    ),
    [Slip Amount]
)

6.pngA Simpler Approach:

Another way to calculate the average check is by dividing the total sales amount by the distinct number of slips:

Average Slip Simple = [TotalSales(F)] / DISTINCTCOUNT(fSales[Cash Slip Number])

This method is more efficient and faster than the previous one, emphasizing the importance of understanding the requirements of each task before choosing the approach.

 

7.png

Conclusion X-Functions like SUMX, AVERAGEX, and others are indispensable tools for dynamic calculations in Power BI. They allow you to replace static calculated columns with more efficient, flexible measures, enhancing both performance and adaptability. Whether you're converting sales to different currencies or calculating averages across grouped data, mastering these functions is essential for any data professional. Let us know if you found these examples and tips helpful—we’d love to hear your feedback!