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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Jinxz_21
Regular Visitor

power bi desktop getting difference with calculate

can someone help me with this

Get_Diff = 
VAR __a = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2022) // value = 5
VAR __b = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2021) // value = 10
VAR __c = CALCULATE(__a - __b) //should be c = -5
return
__c

on visual matrix
2021 display -5 instead of 5
2022 display 10
Get_Diff = -5


if i change VAR __c = CALCULATE(__a + __b)
on visual matrix
2021 display  5
2022 display 10
Get_Diff = 15


how can i make 2021 display to a positive number when getting the difference

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Jinxz_21 , Ideally SUM('sales'[Qnty]) should do

 

I think what you need if

Get_Diff =
VAR __a = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2022) // value = 5
VAR __b = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2021) // value = 10
VAR __c = CALCULATE(__a - __b) //should be c = -5

return

if(isinscope(Table[Year]), SUM('sales'[Qnty]), _C)

 

or Use TI

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

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

View solution in original post

2 REPLIES 2
Jinxz_21
Regular Visitor

@amitchandak 
if(isinscope(Table[Year]), SUM('sales'[Qnty]), _C)
this works , thank you so much

amitchandak
Super User
Super User

@Jinxz_21 , Ideally SUM('sales'[Qnty]) should do

 

I think what you need if

Get_Diff =
VAR __a = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2022) // value = 5
VAR __b = CALCULATE(SUM('sales'[Qnty]),'sales'[Year]=2021) // value = 10
VAR __c = CALCULATE(__a - __b) //should be c = -5

return

if(isinscope(Table[Year]), SUM('sales'[Qnty]), _C)

 

or Use TI

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors