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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Til22
New Member

calculate the variance between rows based on date and variable

Hi,

I am hoping some one can help me.  I have a list of variables, dates and values and I want to calculate the variance in value between dates when the variables are the same.  For example, the variance between Pineapples on 19-Aug and 18-Aug is 1, and the variance between Grapes on 19-Aug and 18-Aug is 4.

 

Til22_0-1629422124547.png

 

 

Any advise would be appreciated.

 

Til22

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Til22 

You can use EARLIER DAX to realize your needs .I create a sample ,you can refer to it .

Original Data :

Ailsamsft_0-1629702012964.png

Then create a calculated column to return the diff .

diff =
var previous_variance =CALCULATE(MAX('Table'[#]),FILTER('Table','Table'[Covid]=EARLIER('Table'[Covid]) && 'Table'[Date]<EARLIER('Table'[Date])))
return 'Table'[#]-previous_variance

The final result is as shown :

Ailsamsft_1-1629702012967.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa 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

2 REPLIES 2
Anonymous
Not applicable

Hi @Til22 

You can use EARLIER DAX to realize your needs .I create a sample ,you can refer to it .

Original Data :

Ailsamsft_0-1629702012964.png

Then create a calculated column to return the diff .

diff =
var previous_variance =CALCULATE(MAX('Table'[#]),FILTER('Table','Table'[Covid]=EARLIER('Table'[Covid]) && 'Table'[Date]<EARLIER('Table'[Date])))
return 'Table'[#]-previous_variance

The final result is as shown :

Ailsamsft_1-1629702012967.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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

VahidDM
Super User
Super User

 Hi @Til22 

 

Try this measure:

Variance = 
VAR _MaxDate =
    MAX ( 'Table'[Date Reported] )
RETURN
    VAR _lastdate =
        CALCULATE (
            MAX ( 'Table'[Date Reported] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Date Reported] < _MaxDate )
        )
    RETURN
        VAR _DateValue =
            MAX ( 'Table'[#] )
        RETURN
            VAR _LastDateValue =
                CALCULATE (
                    MAX ( 'Table'[#] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[Covid Results] ),
                        'Table'[Date Reported] = _lastdate
                    )
                )
            RETURN
                _DateValue - _LastDateValue

 

Output will be as below:

VahidDM_1-1629427596391.png

 

VahidDM_0-1629427575007.png

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_2-1629427621686.png !!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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