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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
CM_Learner
Frequent Visitor

Calculate the difference between values 6 months apart in Power BI

Hi All,

 

I have been using PowerBI for a while now, but I am not really familiar with the DAX terminology and need a bit of help here. I want to create a measure that calculates the difference between two values that are six months apart. I have a table that looks something like this:

 

06/01/2024   0.1
05/01/2024   -0.2
04/01/2024   -0.5
03/01/2024   0
02/01/2024   1
01/01/2024   0.5
12/01/2023   0.3

 

Let's assume it is currently January 2024. What I want to do is calculate the difference between the value 6 months ago (0.5) and this months value (0.1). I would like to do this on a rolling basis as new monthly information is updated in the dashboard. I am not experienced or familiar enough with DAX to be able to figure this problem out. If there is someway I should be doing this that is not a measure and is easier, please point me in that direction, as well.

 

Thank you in advance for any assistance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@CM_Learner Hello,@bhanu_gautam ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.
I am glad to help you.

Have you solved your problem yet?

If the data in your datasheet is updated in real time, and the value for the current month is updated every month, and you want to implement a rolling calculation

You can refer to my test below

vjtianmsft_0-1718259971184.png

vjtianmsft_1-1718260079747.png

 


Here is the DAX code:

 

M_1 = 
VAR max_date= CALCULATE(MAX('Table'[Date]),ALL('Table'))
//max_date:Ignore filters and always get the latest time in a table that is constantly updated
VAR six_BeforeDate= EOMONTH(max_date,-7)+1

VAR values_least=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'[Date]),'Table'[Date]=max_date))
VAR values_lastsixmonth=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'[Date]),'Table'[Date]=six_BeforeDate))
RETURN values_least-values_lastsixmonth

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

5 REPLIES 5
Anonymous
Not applicable

Hi,@CM_Learner Hello,@bhanu_gautam ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.
I am glad to help you.

Have you solved your problem yet?

If the data in your datasheet is updated in real time, and the value for the current month is updated every month, and you want to implement a rolling calculation

You can refer to my test below

vjtianmsft_0-1718259971184.png

vjtianmsft_1-1718260079747.png

 


Here is the DAX code:

 

M_1 = 
VAR max_date= CALCULATE(MAX('Table'[Date]),ALL('Table'))
//max_date:Ignore filters and always get the latest time in a table that is constantly updated
VAR six_BeforeDate= EOMONTH(max_date,-7)+1

VAR values_least=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'[Date]),'Table'[Date]=max_date))
VAR values_lastsixmonth=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'[Date]),'Table'[Date]=six_BeforeDate))
RETURN values_least-values_lastsixmonth

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

bhanu_gautam
Super User
Super User

@CM_Learner , You can create a DAX measure using LAG function

 

Difference = 
VAR CurrentMonthValue = [Value]
VAR SixMonthsAgoValue = LAG([Value], 6)
RETURN CurrentMonthValue - SixMonthsAgoValue



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi, thank you for the feedback. Will this allow the calculation to be relative to the current date or this a static calculation? I need it to roll over into the next month and use the new 6 months values to claculate it each month.

That is static if you want dynamic you can try

 

Difference = 
VAR CurrentMonthValue = [Value]
VAR SixMonthsAgoValue = CALCULATE(
    [Value],
    DATEADD('Table'[Date], -6, MONTH)
)
RETURN CurrentMonthValue - SixMonthsAgoValue



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






What should I be using for the [Value]? I have tried the name of the column, I have tried the 'Table'[Name of column] format. None of these syntaxes are working. It is saying the column doesn't exist

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.