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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mfarali
Frequent Visitor

% difference between years for average sales

Hi,

 

I have a situation where I have sales data from across the years. I would like to show on average what is the % change from one year to the other based on slicer selection. Something like the table low. 

 

I would like to show the % difference between lets say 2018 to 2021 in a line graph based on slicer selection. I have tried to use DAX measures but I cant seem to get it work.

 

Can anyone please help me on this?

 

Screenshot 2022-12-04 151835.png

 

Thanks in advance

 

9 REPLIES 9
mfarali
Frequent Visitor

not really, the difference could be any year vs any year (as chosen in the slicer)

 

So the viewer could select 2019 and 2021. or 2018 and 2019. or any other combo that they want to see the % difference for.

so in any selection, the difference is a single value, why being plotted with year on the x axis?

the difference is a single value if only 2 years are selected. but if the viewer wants to see the trend then they can select more than 2 years to see the changes in %

 

like choosing to see 2018, 2019, 2020 if they wanted to

Hi @mfarali 

 

According to your description, I made a sample and here is my solution. Please follow these steps.

Sample data:

vxiaosunmsft_0-1670230571045.png

Create five columns to calculate totals.

Totals = SUM('Tabelle1'[values])
sum of 2018 = SUMX(FILTER('Tabelle1','Tabelle1'[Year]=2018),'Tabelle1'[values])
sum of 2019 = SUMX(FILTER('Tabelle1','Tabelle1'[Year]=2019),'Tabelle1'[values])
sum of 2020 = SUMX(FILTER('Tabelle1','Tabelle1'[Year]=2020),'Tabelle1'[values])
sum of 2021 = SUMX(FILTER('Tabelle1','Tabelle1'[Year]=2021),'Tabelle1'[values])

Create a calculated column to return the % of each year.

percentage = 
IF('Tabelle1'[Year]=2018,'Tabelle1'[sum of 2018]/'Tabelle1'[Totals],
IF('Tabelle1'[Year]=2019,'Tabelle1'[sum of 2019]/'Tabelle1'[Totals],
IF('Tabelle1'[Year]=2020,'Tabelle1'[sum of 2020]/'Tabelle1'[Totals],
IF('Tabelle1'[Year]=2021,'Tabelle1'[sum of 2021]/'Tabelle1'[Totals]))))

Then create a column to return the changes.

change =
IF (
    'Tabelle1'[Year] = 2018,
    0,
    'Tabelle1'[percentage]
        - CALCULATE (
            MAX ( 'Tabelle1'[percentage] ),
            FILTER ( 'Tabelle1', 'Tabelle1'[percentage] < EARLIER ( Tabelle1[percentage] ) )
        )
)

Finally, put "Year" and "change" into the line chart, you will get the result as below.

vxiaosunmsft_1-1670231030951.png

 

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ xiaosun

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

I tried it out but I think the calculations are off. Sharing a sample here

 

 

Screenshot 2022-12-06 235749.png

the % change is shown as 4.74% between 2018 to 2019 when its a lot more than that. the % increase would be (16,643,485 - 1,687,711)/1,687,711 = 886.15% increase

 

not sure how i can attach the pbix file here.

 

thanks

Thanks  will try it out

FreemanZ
Super User
Super User

what will you put on the x-axis of the line graph?

can i say 2018 is the minimum and 2021 is the maximum of the slicer selection?

The years will be on the x axis. so depending on selection, it could be 2018 to 2021, or 2019 to 2021 etc

the difference is 2018 vs 2021 or 2018 vs 2019, 2019 vs 2020, 2020 vs 2021?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors