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

Variance from column to column

Hello together,

I'm quite new to Power BI. I'm looking for a way to calculate the variance from the values of the current column to the previous one. I have tried variance by category but it wouldn't work. The result would need to look like in the example below:

 

Date20.08.202021.08.202024.08.202026.08.2020
Value50010002000500
Variance to previous column 5001000-1500

 

Any help is highly appreciated.

 

Thank you very much!

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create an index column in query editor and create a measure like this:

Measure =
VAR last_index =
    MAX ( 'Table (2)'[Index] )
VAR last_value =
    CALCULATE (
        FIRSTNONBLANK ( 'Table (2)'[value], 1 ),
        FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Index] = last_index - 1 )
    )
RETURN
    IF (
        MAX ( 'Table (2)'[Index] ) = 1,
        BLANK (),
        MAX ( 'Table (2)'[value] ) - last_value
    )

V-lianl-msft_0-1601966375656.png

 

Sample .pbix

 

Best Regards,
Liang
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

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Create an index column in query editor and create a measure like this:

Measure =
VAR last_index =
    MAX ( 'Table (2)'[Index] )
VAR last_value =
    CALCULATE (
        FIRSTNONBLANK ( 'Table (2)'[value], 1 ),
        FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Index] = last_index - 1 )
    )
RETURN
    IF (
        MAX ( 'Table (2)'[Index] ) = 1,
        BLANK (),
        MAX ( 'Table (2)'[value] ) - last_value
    )

V-lianl-msft_0-1601966375656.png

 

Sample .pbix

 

Best Regards,
Liang
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 , I think You need Day vs day diff with Show on row in Matrix visual . Use a date table

 

This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))

 

variance = [This Day] -[Last Day]

 

Show on Row.png

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi



Appreciate your Kudos.

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.