March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I realized that this was not needed but wanted to understand why this is not calculated correctly.
To make this as simple as possible without screenshots, imagine I have 2 Measures (M1 & M2) for the same table with different Filters.
M1 = 10
M2 = 30
In two other measures I have ways of calculating.
DAX1 = [M1]+[M2]
which = 40
Dax2 = Calculate(SUMX([M1]+[M2]))
Totaling lets say 130
How and why is this happening, could be over looking something here but should this even happen?
@Lamar249 That doesn't look like valid DAX code, SUMX takes a table as a first parameter. If I had to guess, it would be performing the calculation of M1 and M2 for each row of the table, adding them together and then taking the total sum of those rows. But, hard to be sure given the information provided. Also, not sure the CALCULATE is entirely necessary, but that will depend on a lot of things.
You're right about it not being valid, when I typed out the question I forgot to put the table part here is a better example of what was being done. I'm fairly new to PBi, so keep in mind this before I realize I can simply just add all measures together.
@Lamar249 OK, what is the formula for the M3 measure? If it references other measures, will need those measure formulas as well.
OK, so it's really hard to visualize exactly what is going on but here is the jist of it I think. So SUMX is going to calculate M3 for every row of Table1 and then sum all of those results together. Now, M3 is using CALCULATE and CALCULATE replaces filter context and discards row context (see below from dax.guide). So, for each row, any row context is being discarded and you are creating a sum of the rows in the table that fit the filter criteria specified. Then all of those values get summed up. If you want to see what is going on internally, then you could do this:Test Measure = VAR __Table = ADDCOLUMNS('Table1', "__M3", [M3]) VAR __Result = TOCSV( __Table, 100 ) RETURN __ResultYou could use that in a Card visual for example to see what is going on internally within the SUMX essentially, as in the table generated over which the sum is applied. I am *guessing* what is going on is that each row will have the same value because row context is being removed and then the same filter context is applied for each row. Just a guess.
And now you know why the last line of my signature is what it is...
From dax.guide:
CALCULATE evaluation follow these steps:
The filter context generated after point (5) is the new filter context used by CALCULATE in the evaluation of its expression.
With some trial and error, I narrowed it down to the entries in this particular data set that is having the issue. I used your measure above and sorted it to the same data so that I could compare it. There is an extra $81k in the SUMX measure, which I filtered down the dataset to where this is coming from.
I removed all the extra text from your measure to compare the filter query.
Filtered Query | Your Measure |
39683.226 | 39683.226 |
-33670.616 | -33670.616 |
33670.616 | 33670.616 |
-39683.226 | -39683.226 |
40524.9914 | 40524.9914 |
-40524.9914 | -40524.9914 |
40524.9914 | 81049.9828 |
-40524.9914 | -40524.9914 |
39683.226 | 39683.226 |
-39683.226 | -39683.226 |
40524.9914 | 40524.9914 |
-40524.9914 | -40524.9914 |
40524.9914 | 81049.9828 |
-40524.9914 | -40524.9914 |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
15 | |
7 | |
6 |
User | Count |
---|---|
33 | |
29 | |
16 | |
13 | |
12 |