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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AntoineGlacet
Regular Visitor

Cannot use SUMX to sum over a dimension

Hello,

link to the pbix

I cannot get the sum of this measure over "uniqueID".

AntoineGlacet_0-1672057105343.png

The measure is a bit complex, I tried to trim down the attached pbix to the very essential issue.
Basically, I have a measure which depends on 2 context (time_1min, and uniqueID).
I cannot sum over UniqueID... I honestly don't understand why it does not work as is.

I tried

 

    CALCULATE(
    SUMX(
        CALCULATETABLE(
            VALUES(KIX_AODB_data[UniqueID]),
            REMOVEFILTERS(Time_flight)
        ),
        _result_by_flight // measure displayed on screenshot above
    )
    )

 



Seems simple but is actually quite complex I guess

Here is the data model (dead simple).

AntoineGlacet_0-1672057434909.png

 

 

1 ACCEPTED SOLUTION

@AntoineGlacet 
 You have several variables in that piece of code, and variables that in turn use other variables. Drop the variables for now. Use either the explicit code or a measure. Make sure every piece is evaluated where it needs to be.  Once it works, you can go back to, carefully, simplifying with variables. 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

3 REPLIES 3
AlB
Super User
Super User

Hi @AntoineGlacet 

I haven't looked in detail but first thing that stands out is that you are using a variable  (_result_by_flight) as second argument to the SUMX. Not that variables in DAX are immutable, i.e. their values does NOT change at all after being created. That means row context in your SUMX will NOT have any affect and the result of the SUMX will be the precalculated value of _result_by_flight times the number of rows of the table in SUMX's argument.

I am guessing that is not what you want   

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

 

Hi @AlB ,
I think it is clearly an issue of variable evaluation and context.
When I copy pasted the whole variable definition instead of its variable name, I have the same result...
How can I make sure the variable is evaluated in the proper context?

@AntoineGlacet 
 You have several variables in that piece of code, and variables that in turn use other variables. Drop the variables for now. Use either the explicit code or a measure. Make sure every piece is evaluated where it needs to be.  Once it works, you can go back to, carefully, simplifying with variables. 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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