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
pawelj795
Post Prodigy
Post Prodigy

Difference between most recent value and last value

Hi,
I'm currently calculating the difference in Facebook likes between the last update and the most recent update.
Our updates vary, sometimes after 7 days, sometimes after 10 days, sometimes after 14 days.
 
How can I automate this case so that it works every time?
The breakdown by country is not important.


image.png

1 ACCEPTED SOLUTION

@pawelj795 - Sorry, I always mess up dates in non-US form.

 

Measure =
  VAR __MaxDate = MAX('Table'[Update Date])
  VAR __2ndDate = MAXX(FILTER('Table',[Update Date]<>__MaxDate),[Update Date])
  VAR __2ndValue = SUMX(FILTER('Table',[Update Date] = __2ndDate),[Likes])
  VAR __MaxValue = SUMX(FILTER('Table',[Update Date] = __MaxDate),[Likes])
RETURN
  __MaxValue - __2ndValue


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

@pawelj795 - Not sure I 100% follow but I think:

 

Measure =
  (MAX([Update Date]) - MIN([Update Date]) * 1.

 

Kind of interested how you get fractional Likes. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
Thanks for weighing in.

Fractional likes come from rounding percentages 😉 They are not important.


I show below example of my desired results.
I want to calculate difference between value in blue circle and value in red circle.

 
 

image.png

 

@pawelj795 - Ah, you need Lookup Min/Max - https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

Basically, 

 

Measure =
  VAR __MinDate = MIN('Table'[Update Date])
  VAR __MaxDate = MAX('Table'[Update Date])
  VAR __MinValue = SUMX(FILTER('Table',[Update Date] = __MinDate),[Likes])
  VAR __MaxValue = SUMX(FILTER('Table',[Update Date] = __MaxDate),[Likes])
RETURN
  __MaxValue - __MinValue

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I don't think that MIN is appropriate in this case.
 
I need the difference between the most recent value and the second recent value as I shown in the previous photo.
Look at my measure, I only need the last part.

image.png

@pawelj795 - Sorry, I always mess up dates in non-US form.

 

Measure =
  VAR __MaxDate = MAX('Table'[Update Date])
  VAR __2ndDate = MAXX(FILTER('Table',[Update Date]<>__MaxDate),[Update Date])
  VAR __2ndValue = SUMX(FILTER('Table',[Update Date] = __2ndDate),[Likes])
  VAR __MaxValue = SUMX(FILTER('Table',[Update Date] = __MaxDate),[Likes])
RETURN
  __MaxValue - __2ndValue


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
Thanks that works perfectly! I was exactly looking for that.

 

By the way, I have the same issue with US date format 😉

@pawelj795 - Sweet!


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors