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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Werdinkaa
Frequent Visitor

Calculating difference between two calculated measures

Hi, 

I need to calculate variance between two measures however dax returns difference between summed up submeasures:

 

example

 

Sales = Calculate([Total],filter('Category'[KPI] = "Sales")

Other = Calculate([Total],filter('Category'[KPI] = "Other")

Result = [Sales]/[Other]

 

I have the same calculation for Actual and Forecast and using switch to show on matrix based on selected value

 

I have added another measuere "Difference" 

[Difference] = [Actual]-[Forecast]

Werdinkaa_0-1626853945660.png

 

It works perfectly for all other kpis however with division it doesnt calculate difference between Actual nr and Forecast nr ,but sums up Sales for both and Other for boths 

 

Can you help please?

 

 

 

7 REPLIES 7
Anonymous
Not applicable

Hi @Werdinkaa ,

 

Create a KPI table as below.

4.PNG

Then create measures as below.

 

Actual = 
var _sales = CALCULATE(SUM(Data[Amount]),FILTER(ALLSELECTED(Data),Data[Category]="actual"&&'Data'[KPI]="sales"&&Data[Period]=SELECTEDVALUE(Period[Period])))
var _other = CALCULATE(SUM(Data[Amount]),FILTER(ALLSELECTED(Data),Data[Category]="actual"&&'Data'[KPI]="other"&&Data[Period]=SELECTEDVALUE(Period[Period])))
var _percent = _sales/_other
return
IF(SELECTEDVALUE('KPI'[KPI])="%",_percent,CALCULATE(SUM(Data[Amount]),Data[Category]="actual"))

Forecast = 
var _sales = CALCULATE(SUM(Data[Amount]),FILTER(ALLSELECTED(Data),Data[Category]="forecast"&&'Data'[KPI]="sales"&&Data[Period]=SELECTEDVALUE(Period[Period])))
var _other = CALCULATE(SUM(Data[Amount]),FILTER(ALLSELECTED(Data),Data[Category]="forecast"&&'Data'[KPI]="other"&&Data[Period]=SELECTEDVALUE(Period[Period])))
var _percent = _sales/_other
return
IF(SELECTEDVALUE('KPI'[KPI])="%",_percent,CALCULATE(SUM(Data[Amount]),Data[Category]="forecast"))

variance = [Actual]-[Forecast] 

 

Result would be shown as below.

5.PNG

Pbix as attached.

 

Best Regards,

Jay

Hi @Anonymous , Thanks however this is not sufficient - I have only put example, in real model we have around 30-40 kpis based on few milion rows , and its not only actual forecast but other categorys too ( previous quaters etc). But thanks

Werdinkaa
Frequent Visitor

@amitchandak Hey, do you have any ideas for solution? I would really appriciate

amitchandak
Super User
Super User

@Werdinkaa , There seems to be a measure split on row and column?

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak Did the link work? Do you maybe have a solution?

 

Thanks in advance

@Werdinkaa , I check it, can you tell what is expected number is in the file, They are different from what you shared here

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.