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
Anonymous
Not applicable

Percent Difference of same column but different year

Hi all,

 

I want to show to perecent differnce of year 2020 and 2021 for column A_ Total CO2. Does someone know the formula for this?

Lola_22_0-1643122960029.png

 

Thanks in advance!

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

Hi @Anonymous ,

 

You are trying to calculate the percentage change between the current year and the previous year, right?

From your screenshot, I guess you should also have a column similar to my Group column below that groups the years.

Try this measure

Percentage =
VAR _preyear =
    CALCULATE (
        SUM ( 'Table'[A_Total CO2] ),
        FILTER (
            ALL ( 'Table' ),
            [Group] = MAX ( 'Table'[Group] )
                && [Year]
                    = MAX ( 'Table'[Year] ) - 1
        )
    )
RETURN
    DIVIDE ( SUM ( 'Table'[A_Total CO2] ) - _preyear, _preyear )

vstephenmsft_0-1643353079259.png

 

 

Best Regards,

Stephen Tao

 

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-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You are trying to calculate the percentage change between the current year and the previous year, right?

From your screenshot, I guess you should also have a column similar to my Group column below that groups the years.

Try this measure

Percentage =
VAR _preyear =
    CALCULATE (
        SUM ( 'Table'[A_Total CO2] ),
        FILTER (
            ALL ( 'Table' ),
            [Group] = MAX ( 'Table'[Group] )
                && [Year]
                    = MAX ( 'Table'[Year] ) - 1
        )
    )
RETURN
    DIVIDE ( SUM ( 'Table'[A_Total CO2] ) - _preyear, _preyear )

vstephenmsft_0-1643353079259.png

 

 

Best Regards,

Stephen Tao

 

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

 

 

amitchandak
Super User
Super User

@Anonymous , with a separate date or year table you can have measure like example

//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

 

//exact year

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=2020))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=2021))

 

diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

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

OR you could use "Sameperiodlastyear"

so

CO2 = Calculate(sum('Table'[Qty])

C02, LY = calculate(CO2),SAMEPERIODLASTYEAR('Calendertable'[DateValue]))

 

 

This has the added value that if you set a filter  that exclude dates that is after today, it will only compare for the same date on last year, so you can compare incomplete years directly

 

EG.

you set filter for no dates after to day

then you get 2022-01-01 .. 2022-01-25   compared to 2021-01-01..2021-01-25 

and if you remove the no dates after today, then you get the full 2021 ... we use this alot

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.