Forum Discussion
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
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 = -5return
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
2 Replies
- amitchandak
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 = -5return
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 - Jinxz_21Regular Visitor
amitchandak
if(isinscope(Table[Year]), SUM('sales'[Qnty]), _C)
this works , thank you so much