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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PbI_Fox
Regular Visitor

Summarize doesnt work when VARs are in it

Hello,

 

I have issues with what i think is the order of VAR calculations in my measure.

 

The code here works:

 

 

NDR_WC =
VAR WC_Table =
    SUMMARIZE (
        Astute_Export,
        Astute_Export[EmployeeID],
        "TableWC", CALCULATE (
            IF (
                ISBLANK (
                    CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Oncost" )
                ),
                CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Payment" ),
                CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Oncost" )
            )
        )
    )
RETURN
    SUMX ( WC_Table, [TableWC] )

 

 

 

However if i change line 9 CALCULATE function in to a var, for example, it stops working and is giving me the wrong number. How to make this code work?

 

 

 

NDR_WC =
VAR Oncost_WC_Calc =
    //Calculates WC existing in OnCost sections
    CALCULATE (
        SUMX ( Astute_Export, [NDR_Step1] ),
        Astute_Export[Type] = "Oncost"
    )
VAR Payment_WC_Calc =
    //Calculates WC existing in Payment sections
    CALCULATE (
        SUMX ( Astute_Export, [NDR_Step1] ),
        Astute_Export[Type] = "Payment"
    )
VAR WC_Table =
    SUMMARIZE (
        Astute_Export,
        Astute_Export[EmployeeID],
        "TableWC", IF ( ISBLANK ( Oncost_WC_Calc ), Payment_WC_Calc, Oncost_WC_Calc )
    )
RETURN
    SUMX ( WC_Table, [TableWC] )

 

 

2 REPLIES 2
harshnathani
Community Champion
Community Champion

Hi @PbI_Fox ,

 

When a variable is calculated and stored, it is static.

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/VARs-inside-SUMMARIZE-dont-work/m-p/1266694#M...

 

Regards,

Harsh Nathani

lbendlin
Super User
Super User

Think about what you want to achieve, and then investigate how your context modifiers may mess with it.  VARs help you to avoid some modifiers'  impact, but they can also enforce the impact. If you are falmiliar with the EARLIER() function - that's basically what VARs do - they provide you a snapshot of an "earlier" context.

 

There's a secondary function that VARs fulfill, and it's an ironic one. They help you to avoid calculating the same thing multiple times, and in that respect they are actually constants, not variables.    But that part is not overly applicable to your situation.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.