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
Uka
Frequent Visitor

Calculate the difference in values between previous dates

Hello,

 

Please can you help me to return the difference between two values within some given dates as below;

Uka_0-1697732851986.png

So, I would like to substract the previous date value from the current one ie ((Eng FullTime) on the 13/10/2023) - ((Eng FullTime) on the 06/10/2023)

 

The (Eng Fulltime) is a measure that was calclulated as below; 

Eng FullTime = CALCULATE(DISTINCTCOUNT('ENG SOB'[Employee]), FILTER('ENG SOB', 'ENG SOB'[Groups] = "Engineer"))

Many thanks in advance!
1 ACCEPTED SOLUTION

Hi @Greg_Deckler ,

 

Many thanks for your assistance!

 

I have now figured it out using the following;

Weekly Difference =
Var _selecteddate = VALUES('Date Friday Only'[Date])
var _maxdate = MAXX(_selecteddate, 'Date Friday Only'[Date])
var _value2 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate)
var _value3 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate -7)

Return
_value2 - _value3

_value3 has -7 because the dates occur every 7 days, thus returns the date for the previous week
 
Thanks

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@Uka See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



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...

Hello @Greg_Deckler ,

 

The solution did not work for me as I got a wired result as below;

Uka_0-1697739166328.png

Below is the code that I used;

#Result =
  VAR __Current = CALCULATE(DISTINCTCOUNT('ENG SOB'[Employee]), FILTER('ENG SOB', 'ENG SOB'[Groups] = "Engineer"))
  VAR __PreviousDate = MAXX(FILTER('ENG SOB','ENG SOB'[Operational Date] < EARLIER('ENG SOB'[Operational Date])),[Operational Date])
  VAR __Previous = MAXX(FILTER('ENG SOB',[Operational Date]=__PreviousDate),[Eng FullTime])
RETURN
  __Current - __PreviousDate

@Greg_Deckler Please can you offer another method?


Greg_Deckler
Community Champion
Community Champion

@Uka Post your sample data as text/table and I'll take a look.



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...

Hi @Greg_Deckler ,

 

Many thanks for your assistance!

 

I have now figured it out using the following;

Weekly Difference =
Var _selecteddate = VALUES('Date Friday Only'[Date])
var _maxdate = MAXX(_selecteddate, 'Date Friday Only'[Date])
var _value2 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate)
var _value3 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate -7)

Return
_value2 - _value3

_value3 has -7 because the dates occur every 7 days, thus returns the date for the previous week
 
Thanks
Greg_Deckler
Community Champion
Community Champion

@Uka That works!



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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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