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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Fowmy
Super User
Super User

Different Grand Total - Calculate vs SUMX

Hi,

 

I need to some help in understanding the following problem. Comp Sales (Calculate) measures returns incorrect values at total level, the correct amount is  -2,180.00 which is produced by the Comp Sales  (SUMX.) version I am struggling to find the break of -9,961 using different approaches like CONCATENATEx to know how Calculate behaves at total level but no clues so far.   

 

I am trying to use the Calculate version of the solution as my actual data set is huge.   

 

I have attached the PBIX file. Attachment

 

Comp Sales-1.PNG

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

1 ACCEPTED SOLUTION

Right, so CALCULATE is not the way to go here, SUMX is the way to go. If you think about this, in your CALCULATE formula, you are doing a FILTER on the CROSSJOIN of ALL rows in your table with your DATE table, and hence your wrong answer. The way SUMX works is that the first part is that you are creating a table with your CROSSJOIN where your Sales Growth is calculated per line and then you SUM up that column in that resulting table, which is why you get the right answer. Hence why the Measure Totals: The Final Word uses the "X" aggregation functions like SUMX.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
themistoklis
Community Champion
Community Champion

@Fowmy

 

Try the following:

 

SUMX (
                VALUES ( TableName[STORE] );
                CALCULATE ( SUM ( TableName[Comp Sales] ) )
            )
Greg_Deckler
Super User
Super User

Can you post your formula for the measure that is not working correctly? I prefer not to download PBIX files. This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks, Greg,

 

I will have a look at the links you have provided, meanwhile, these are the measures I have used. 

 

Total Sales = SUM(Sales[Sales Amount])

Total Sales LY = CALCULATE([Total Sales],DATEADD('DATE'[Date],-1,YEAR))

Sales Growth = [Total Sales]-[Total Sales LY]

Comp Sales (Calculate) = 
CALCULATE([Sales Growth]
    ,FILTER(
        CROSSJOIN(VALUES('DATE'[Date]),Branch)
        ,'DATE'[Date]>EOMONTH(Branch[Open Date],12)
    )
)

Comp Sales (SUMX) = 
SUMX(
    FILTER(
        CROSSJOIN(VALUES('DATE'[Date]),Branch)
        ,'DATE'[Date]>EOMONTH(Branch[Open Date],12)
    )
    ,[Sales Growth]
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Right, so CALCULATE is not the way to go here, SUMX is the way to go. If you think about this, in your CALCULATE formula, you are doing a FILTER on the CROSSJOIN of ALL rows in your table with your DATE table, and hence your wrong answer. The way SUMX works is that the first part is that you are creating a table with your CROSSJOIN where your Sales Growth is calculated per line and then you SUM up that column in that resulting table, which is why you get the right answer. Hence why the Measure Totals: The Final Word uses the "X" aggregation functions like SUMX.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.