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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PBI_LUCKY
Frequent Visitor

Calculate the variance of the rows above

Hi team,

 

Is there a way in PBI that we can calculate the difference of the rows above? Refer to the table below:

  • I would like to calculate the different between sale in 2024 and 2022 for each month. The year can be change (e.g 2021 vs 2023, so it is not comparing current year to prior year). Result is the last 2 rows.

Thanks

 

YearTypeJanFebMarAprMayJunJulAugSepOctNovDecTOTAL
2024Sale505050505050505050505050600
 Cost202020202020202020202020240
2022Sale303030303030303030303030360
 Cost101010101010101010101010120
VarSale202020202020202020202020240
 Cost101010101010101010101010120
5 REPLIES 5
Anonymous
Not applicable

Hi @PBI_LUCKY ,

 

Try the following expression:

PreviousYearSameMonthDifference = 
VAR CurrentMonth = MONTH(MAX('Table'[Date]))
VAR CurrentYear = YEAR(MAX('Table'[Date]))
VAR PreviousYear = CurrentYear - 2
RETURN
CALCULATE(
    SUM('Table'[Sales]),
    FILTER(
        ALL('Table'),
        YEAR('Table'[Date]) = PreviousYear &&
        MONTH('Table'[Date]) = CurrentMonth
    )
) - SUM('Table'[Sales])

 

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Thanks but it is no the way I want it. I want the calculation to be dynamic. It means I can compare not only 2022 vs 2024 but also other e.g 2020 vs 2024.

Anonymous
Not applicable

Hi @PBI_LUCKY ,

 

You can create a parameter that changes PreviousYear to the following expression:

 

VAR PreviousYear = CurrentYear - [parameter]

 

Use parameters to visualize variables - Power BI | Microsoft Learn

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

lbendlin
Super User
Super User

Yes, this can be done with Visual Calculations which actually has a concept of "the row above".  Give that a try.

Thanks but it doesn't work since it is only allowed adding the column but not the row. I think the dataset was set up that all value is in the same column (e.g in the dataset sales & exp amount are on the same column and there is an extra column next to it definte whether it is sales or exp). Cheers

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.