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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
LukeWalker
Advocate IV
Advocate IV

Variable Value Changes Based on Return Expression Bug

I have the following measure:

Y/Y Price Inflation = 
VAR MaxDate = MIN(MAX('Calendar'[Date]),TODAY())
RETURN
CALCULATE(
        VAR Num = [Cumulative Price Inflation]
        VAR Denom = CALCULATE([Cumulative Price Inflation],FILTER(ALL('Calendar'),'Calendar'[Date]<MaxDate-365))
    RETURN
        DIVIDE(Num-Denom,Denom+1),
    FILTER(LookBehind,LookBehind[n]=1)
)

 

The issue is the RETURN statement on line 8. If I only reference the Num variable (RETURN Num), I get the expected result. However, if I reference Num and Denom (RETURN Num-Denom) or any other combination with both variables, a different value is used for Num, all else equal. I am not sure where this other result is coming from. Could this be some context bug or something? I'm at my wit's end on this one. I am running the May 2018 version.

 

Cumulative Price Inflation = 
VAR MaxDate = MIN(MAX('Calendar'[Date]),TODAY())
VAR LookBack = MAX(LookBehind[Days])
VAR AllCal = FILTER(ALL('Calendar'),'Calendar'[Date]<=MaxDate)
VAR ThisPer = FILTER(AllCal,'Calendar'[Date]>MaxDate-LookBack)
RETURN
DIVIDE(
    SUMX(item_all,
        VAR MinPODate = CALCULATE(MIN(po_mst[order_date]),AllCal)
        VAR MaxPODate = CALCULATE(MAX(po_mst[order_date]),AllCal)
        VAR RelatedPO = RELATEDTABLE(poitem_mst)
        VAR Denom = CALCULATE(DIVIDE(SUM(poitem_mst[Line Cost]),SUM(poitem_mst[Line Qty])),FILTER(AllCal,'Calendar'[Date] = MinPODate))
        VAR Num = CALCULATE(DIVIDE(SUM(poitem_mst[Line Cost]),SUM(poitem_mst[Line Qty])),FILTER(AllCal,'Calendar'[Date] = MaxPODate))
        RETURN
       IF(OR(ISBLANK(Num),ISBLANK(Denom)),BLANK(),DIVIDE(Num-Denom,Denom))*CALCULATE([Hist_Agg.Cost],ThisPer)
    ),
    CALCULATE([Hist_Agg.Cost],ThisPer)
)

 

Regards,

Luke

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@LukeWalker,

 

DAX Studio can be used to capture queries, you may have a look.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

That's super helpful. It looks like it's changing "Num"  when it's combined with "Denom".

 

"RETURN Num" evaluates to X

"RETURN Num + Denom * 0" evaluates to a value different from X

 

I'm still clueless as to why, but now I kind of know what's going on at least.

 

Can variables be passed between measures? There are some variable names defined in this measure (Y/Y Price Inflation) that are also used in the dependent measure (Cumulative Price Inflation). However, changing the names doesn't fix the problem either..

 

I've also tried running the "Num" inside a CALCULATE(ALL('Calendar'),...)  clause, but that doesn't fix it.

 

	CALCULATE([Cumulative Price Inflation],FILTER(ALL('Calendar'),'Calendar'[Date]<TODAY()))
	- CALCULATE([Cumulative Price Inflation],FILTER(ALL('Calendar'),'Calendar'[Date]<TODAY()- 365)) * 0
	=
	CALCULATE([Cumulative Price Inflation],FILTER(ALL('Calendar'),'Calendar'[Date]<TODAY())

 The above returns "TRUE". However when the two clauses are run independently, they do not equal each other.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors