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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gujralh
Helper I
Helper I

How to create the measure for getting the Value difference between 2 dates

Hi All

 

Please help me in creating the measure for getting the value difference between 2 dates i.e Existing date with last 7th date.

 

Here in below table values against each date is also a measure. So I want another measure which gives difference b/w last date (7/9/2024) and last date - 7 ( (7/3/2024) = 0.005 (99.866-99.861).

3rd measure would be their % difference i.e (0.005/last day-7 value)*100

 

gujralh_0-1720645030840.png

 

Thanks!

 

1 ACCEPTED SOLUTION

Hi @gujralh ,

 

Thank you for your reply.

 

Please create the following two measures to show the value difference and % value difference for dates every seven days:

vyajiewanmsft_0-1721030225246.png

 

Measure_Difference_7Days = 
VAR CurrentDate = MAX('Table'[Date_ID])
VAR PreviousDate = CurrentDate - 6
VAR MeasureCurrent = [Measure1]
VAR MeasurePrevious =
   CALCULATE(
       [Measure1],
       FILTER(
           ALL('Table'),
           'Table'[Date_ID] = PreviousDate
       )
   )
RETURN
   IF(
       ISBLANK(MeasurePrevious),
       BLANK(),
       MeasureCurrent - MeasurePrevious
   )

 

vyajiewanmsft_1-1721030269111.png

 

Measure_Difference_Percentage_7Days = 
VAR CurrentDate = VALUE(MAX('Table'[Date_ID]))
VAR PreviousDate = CurrentDate - 6
VAR MeasureCurrent = [Measure1]
VAR MeasurePrevious =
   CALCULATE(
       [Measure1],
       FILTER(
           ALL('Table'),
           VALUE('Table'[Date_ID]) = PreviousDate
       )
   )
VAR MeasureDifference =
   IF(
       ISBLANK(MeasurePrevious),
       BLANK(),
       MeasureCurrent - MeasurePrevious
   )
RETURN
       MeasureDifference / MeasurePrevious

 

 Result for your reference:

vyajiewanmsft_2-1721030312627.png

Best regards,

Joyce

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
gujralh
Helper I
Helper I

@v-yajiewan-msft  Do we have any solution to get the output against each date??

Hi @gujralh ,

 

Thank you for your reply.

 

Please create the following two measures to show the value difference and % value difference for dates every seven days:

vyajiewanmsft_0-1721030225246.png

 

Measure_Difference_7Days = 
VAR CurrentDate = MAX('Table'[Date_ID])
VAR PreviousDate = CurrentDate - 6
VAR MeasureCurrent = [Measure1]
VAR MeasurePrevious =
   CALCULATE(
       [Measure1],
       FILTER(
           ALL('Table'),
           'Table'[Date_ID] = PreviousDate
       )
   )
RETURN
   IF(
       ISBLANK(MeasurePrevious),
       BLANK(),
       MeasureCurrent - MeasurePrevious
   )

 

vyajiewanmsft_1-1721030269111.png

 

Measure_Difference_Percentage_7Days = 
VAR CurrentDate = VALUE(MAX('Table'[Date_ID]))
VAR PreviousDate = CurrentDate - 6
VAR MeasureCurrent = [Measure1]
VAR MeasurePrevious =
   CALCULATE(
       [Measure1],
       FILTER(
           ALL('Table'),
           VALUE('Table'[Date_ID]) = PreviousDate
       )
   )
VAR MeasureDifference =
   IF(
       ISBLANK(MeasurePrevious),
       BLANK(),
       MeasureCurrent - MeasurePrevious
   )
RETURN
       MeasureDifference / MeasurePrevious

 

 Result for your reference:

vyajiewanmsft_2-1721030312627.png

Best regards,

Joyce

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

 

Thanks much @v-yajiewan-msft, works well for me now!

v-yajiewan-msft
Community Support
Community Support

Hi @gujralh ,

Depending on your requirements, we can create following measures to meet your needs.

 

We start by creating a measure called maxDateValue to get the value of the latest date in the table:

 

maxDateValue = VAR maxDate= MAX('Table'[Date_ID])

VAR maxDateValue=CALCULATE([Measure1],FILTER('Table','Table'[Date_ID]=maxDate))

RETURN maxDateValue

 

We then create a new measure called maxDateValueBefore7 in the same way to get the value corresponding to the seven days younger than maxDate:

 

maxDatebefore7Value = VAR maxDate= MAX('Table'[Date_ID])

VAR maxDateValue=CALCULATE([Measure1],FILTER('Table','Table'[Date_ID]=maxDate))

VAR maxDatebefore7=maxDate-6

VAR maxDatebefore7Value=CALCULATE([Measure1],FILTER('Table','Table'[Date_ID]=maxDatebefore7))

RETURN

maxDatebefore7Value

 

Later, we can use the previous two measures to create the destination measures as shown below:

 

ValueDifference = [maxDateValue]-[maxDatebefore7Value]

 

vyajiewanmsft_0-1720666051367.png

 

%difference = ([ValueDifference]/[maxDatebefore7Value])*100

 

vyajiewanmsft_1-1720666096866.png

Result for your reference:

vyajiewanmsft_2-1720666112553.png

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

 

Best regards,

 

Joyce

 

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

Thanks @v-yajiewan-msft , single output wise it giving ok but i need it for all dates and calculate for all upcoming dates.

 

Against each dates, how it will give the value difference and %value difference with respect to last 7 days.

With provided sloution , here reflecting same values/infinity  against each date

 

gujralh_2-1720723073097.png

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.