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
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
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.