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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
markefrody
Post Patron
Post Patron

Value Difference Between 2 Consecutive Dates

Hi everybody,

 

I'm trying via DAX to get the difference between 2 consecutive dates but I'm having a difficult time in creating it. Weekend (Saturday and Sunday) should be excluded in the calculations. 

 

For example:

For Plan Date "8/8/2023" (Tuesday) with a count of "17" will be compared to the previous weekday which is "8/7/2023" (Monday) with a count of "16". So the calculation would be "17 - 16 = 1". Please note that these 2 dates are weekdays (not Saturday nor Sunday).

markefrody_1-1692748648913.png


For Plan Date "8/7/2023" (Monday) with a count of "16" will be compared to the previous weekday which is "8/4/2023" (Friday) with a count of "16". So the calculation would be "16 - 16 = 0". Please note that date "8/5/2023" is not included in the calculation because it is a Saturday. Saturday and Sundays needs to be excluded in the calculation.

markefrody_2-1692748899606.png


Please note that this calculation needs to be done for similar named groups only in column "Group". So for example, Group A will need to get the difference between 2 consecutive dates for Group A only.  So for Group B, get difference between 2 consecutive dates for Group B only.


Sharing to you a sample file in Power BI containing the raw data.
https://www.dropbox.com/scl/fi/l2dk6lgjxm7p3m4r2hxio/Example.pbix?rlkey=30zlbdiv3210siznebijaafhv&dl...

Appreciate your kind assistance. 

Best regards,
Mark V

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @markefrody 

Thanks for your sample pbix file first! Here are the steps for your need.

We can create a measure like this:

 

Measure = var _t = SUMMARIZE(ALLSELECTED('Data3') ,'Data3'[Plan Date MM/DD/YYYY],'Data3'[Group],Data3[Weekday],"Count",SUM('Data3'[Count]))
var _cur_group = MAX('Data3'[Group])
var _t2= FILTER(_t , [Group] = _cur_group)
var _cur_date = MAX('Data3'[Plan Date MM/DD/YYYY])
var _t3 = FILTER(_t2 , [Plan Date MM/DD/YYYY]<_cur_date && NOT( [Weekday] in {6,7}))
var _pre_date = MAXX(_t3 , [Plan Date MM/DD/YYYY])
return
IF(MAX('Data3'[Weekday]) in {6,7} , BLANK() , SUM('Data3'[Count]) - SUMX(FILTER(_t3 , [Plan Date MM/DD/YYYY] = _pre_date) , [Count]))
 
Then we can put this measure on your visual , and we can get the result as follows:
vyueyunzhmsft_0-1692883030025.png

 

 

Best Regards,

Aniya Zhang

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

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @markefrody 

Thanks for your sample pbix file first! Here are the steps for your need.

We can create a measure like this:

 

Measure = var _t = SUMMARIZE(ALLSELECTED('Data3') ,'Data3'[Plan Date MM/DD/YYYY],'Data3'[Group],Data3[Weekday],"Count",SUM('Data3'[Count]))
var _cur_group = MAX('Data3'[Group])
var _t2= FILTER(_t , [Group] = _cur_group)
var _cur_date = MAX('Data3'[Plan Date MM/DD/YYYY])
var _t3 = FILTER(_t2 , [Plan Date MM/DD/YYYY]<_cur_date && NOT( [Weekday] in {6,7}))
var _pre_date = MAXX(_t3 , [Plan Date MM/DD/YYYY])
return
IF(MAX('Data3'[Weekday]) in {6,7} , BLANK() , SUM('Data3'[Count]) - SUMX(FILTER(_t3 , [Plan Date MM/DD/YYYY] = _pre_date) , [Count]))
 
Then we can put this measure on your visual , and we can get the result as follows:
vyueyunzhmsft_0-1692883030025.png

 

 

Best Regards,

Aniya Zhang

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

Hi Aniya. Your DAX is awesome! I finally got the results I wanted. Thank you very much! Really appreciate your help.

amitchandak
Super User
Super User

@markefrody , There are a few ways we can create last noncontinuous day

 

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

 

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =calculate( max(Sales[Sales Date]), FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])))))

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.