Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi All ,
I am trying to create a variance of shipment from budgeted. However , the customer allows permissible variance which I am trying to build in DAX function. the below function is returning zero for all. Here are the conditions I am trying to build.
| If Variance (shipment-budgeted) is > 0 ; then report the actual varaiance | Eg : Variance = 15 ; result =15 |
| If Variance is less than 0 but greater than -5 , then report vairance as 0 | Eg : Variance = - 4; result = 0 |
| If variance is less than -5 , then add 5 to the actual variance | Eg : Variance = -25 , result = -20 |
Here is the function I am using . I think >=0 <= -5 condition is incorrect , but really dont know how to write. really appreciate any help!
Solved! Go to Solution.
@Anonymous
Can you the values in the columns and the filter context on which you are running this measure?
Try the following:
varianceMod =
VAR Forecast =CALCULATE ( SUM ( 'Monthly Budget'[Order Budget] ) )
VAR VarianceR = [Shipment_tons] - Forecast
VAR switchFnc =
SWITCH (
TRUE (),
VarianceR > 0, VarianceR,
VarianceR >= -5
&& VarianceR <= 0, 0,
VarianceR < -5, VarianceR + 5
)
RETURN
switchFnc
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@Anonymous
Can you the values in the columns and the filter context on which you are running this measure?
Try the following:
varianceMod =
VAR Forecast =CALCULATE ( SUM ( 'Monthly Budget'[Order Budget] ) )
VAR VarianceR = [Shipment_tons] - Forecast
VAR switchFnc =
SWITCH (
TRUE (),
VarianceR > 0, VarianceR,
VarianceR >= -5
&& VarianceR <= 0, 0,
VarianceR < -5, VarianceR + 5
)
RETURN
switchFnc
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
What could be the reason , when the above variance is put in a matrix the row total gives incorrect results (Budget and shipmet totals are correct) ? I checked all the filters , but cannot figure out the reason.
What could be the reason , when the above variance is put in a matrix the row total gives incorrect results (Budget and shipmet totals are correct) ? I checked all the filters , but cannot figure out the reason.
@Anonymous can you reverse the switch order and try
SWITCH(TRUE(),
VarianceR<-5,VarianceR+5,
VarianceR>=-5&&VarianceR<=0,0,
VarianceR>0,VarianceR,)
Hi @Anonymous ,
That expression seems to be working on my end when I've built it in a simple model, could it be something with your relationships that's causing the issue?
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.