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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
melnaggar
New Member

Change Calculation (Yearly & Monthly)

Hi everyone, 

 

I have a data set similar to the below table.  I want to calculate the Monthly and annual change between 2020-2019  2020-2018. 

 

Appreciate your support 

 

Cheers!

Year Collection DateMonthProduct AProduct BProduct C
20181/31/2018123753.3
20182/28/2018221693.3
20183/31/2018324783.3
20184/30/2018421683.2
20185/31/2018519633.2
20186/30/2018616493.1
20187/31/2018721612.9
20188/31/2018822642.9
20189/30/2018920593.0
201810/30/20181021663.2
201811/30/20181123723.2
201812/31/20181225803.2
20191/31/2019124773.2
20192/28/2019222713.2
20193/31/2019324793.3
20194/30/2019424793.2
20195/31/2019515493.3
20196/30/2019622612.8
20197/31/2019722652.9
20198/31/2019823682.9
20199/30/2019921643.0
201910/30/20191023733.2
201911/30/20191124783.3
201912/31/20191227853.2
20201/31/2020127873.3
20202/28/2020222713.3
20203/31/2020311413.9
20204/30/202043206.9
20205/31/202054235.2
20206/30/202066234.1
20207/31/2020710293.1
20208/31/2020814402.9
20209/30/2020911413.8
202010/30/20201013503.8
202011/30/20201112504.2
202012/31/20201217673.9

 

@amitchandak 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @melnaggar ;

You could unpivot it or create a new table as follows:

vyalanwumsft_0-1643695615498.png

Then create a measure to calculate a year change.

Charges = 
VAR _lastyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
VAR _lastyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
VAR _lastyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
return 
 SWITCH(MAX('Table'[cate]),"Product A",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product A])- _lastyeara,_lastyeara),DIVIDE( _maxyeara-_minyeara,_minyeara))),
 "Product B",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product B])- _lastyearB,_lastyearB),DIVIDE( _maxyearB-_minyearB,_minyearB))),
 "Product C",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product C])- _lastyearC,_lastyearC),DIVIDE( _maxyearC-_minyearC,_minyearC))))

The final output is shown below:

vyalanwumsft_1-1643695718605.png

It makes it easier to give you a solution  if you could share the results you want to output, and screenshots would be fine.


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @melnaggar ;

You could unpivot it or create a new table as follows:

vyalanwumsft_0-1643695615498.png

Then create a measure to calculate a year change.

Charges = 
VAR _lastyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyeara=CALCULATE(SUM(Data[Product A]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
VAR _lastyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyearB=CALCULATE(SUM(Data[Product B]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
VAR _lastyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MAX([Year ])-1))
VAR _minyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MINX(ALL(Data),[Year ])))
VAR _maxyearC=CALCULATE(SUM(Data[Product C]),FILTER(ALLSELECTED(Data),[Year ]=MAXX(ALL(Data),[Year ])))
return 
 SWITCH(MAX('Table'[cate]),"Product A",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product A])- _lastyeara,_lastyeara),DIVIDE( _maxyeara-_minyeara,_minyeara))),
 "Product B",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product B])- _lastyearB,_lastyearB),DIVIDE( _maxyearB-_minyearB,_minyearB))),
 "Product C",IF(MAX([Year ])=MINX(ALL(Data),[Year ]),1,IF(ISFILTERED('Data'[Year ]),DIVIDE( SUM([Product C])- _lastyearC,_lastyearC),DIVIDE( _maxyearC-_minyearC,_minyearC))))

The final output is shown below:

vyalanwumsft_1-1643695718605.png

It makes it easier to give you a solution  if you could share the results you want to output, and screenshots would be fine.


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

melnaggar
New Member

@amitchandak  Thank you so much it was very helpful.

 

Is there any other way to calculate the change as a percentage (YTD, MTD) without merging products columns to one column? 

 

amitchandak
Super User
Super User

@melnaggar , Check if attached file can help

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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