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
ZR1
New Member

Number of days between 2 dates in the same column

Hi

 

I am looking to calculate the number of days between different Status's. This will beed to be calculated based on a 24 hour basis too so if this is more than 24 hours, if should be counted as another day. The dates are in the same column.

 

See below for example table

 

 

IDDate Status
120/03/2024Completed
213/03/2024Submitted
110/03/2024Sumbitted
221/03/2024Completed
116/03/2024Approval Needed
218/03/2024Approval Needed

 

This is what I want it to show

 

ZR1_1-1711379220527.png

I would also like some help on not counting weekends and bank holiday days. Can this be done?

 

@amitchandak @Greg_Deckler @lbendlin @AmiraBedh 

 

Thanks

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@ZR1 PBIX is attached. Here is the measure though:

Days = 
    VAR __ID = MAX('Table'[ID])
    VAR __Pair = MAX('Pairs'[Value])
    VAR __Start =
        SWITCH(
            __Pair,
            "Submitted - Approval Needed", MINX(FILTER('Table', [ID] = __ID && [Status] = "Submitted"), [Date ]),
            "Approval Needed - Completed", MAXX(FILTER('Table', [ID] = __ID && [Status] = "Approval Needed"), [Date ]),
            BLANK()
        )
    VAR __End =
        SWITCH(
            __Pair,
            "Submitted - Approval Needed", MINX(FILTER('Table', [ID] = __ID && [Status] = "Approval Needed"), [Date ]),
            "Approval Needed - Completed", MAXX(FILTER('Table', [ID] = __ID && [Status] = "Completed"), [Date ]),
            BLANK()
        )
    VAR __Result = ( __End - __Start ) * 1.
RETURN
    __Result


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

5 REPLIES 5
ZR1
New Member

Just amended the post to include the table as text

Greg_Deckler
Community Champion
Community Champion

@ZR1 PBIX is attached. Here is the measure though:

Days = 
    VAR __ID = MAX('Table'[ID])
    VAR __Pair = MAX('Pairs'[Value])
    VAR __Start =
        SWITCH(
            __Pair,
            "Submitted - Approval Needed", MINX(FILTER('Table', [ID] = __ID && [Status] = "Submitted"), [Date ]),
            "Approval Needed - Completed", MAXX(FILTER('Table', [ID] = __ID && [Status] = "Approval Needed"), [Date ]),
            BLANK()
        )
    VAR __End =
        SWITCH(
            __Pair,
            "Submitted - Approval Needed", MINX(FILTER('Table', [ID] = __ID && [Status] = "Approval Needed"), [Date ]),
            "Approval Needed - Completed", MAXX(FILTER('Table', [ID] = __ID && [Status] = "Completed"), [Date ]),
            BLANK()
        )
    VAR __Result = ( __End - __Start ) * 1.
RETURN
    __Result


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 Thank you so much

 

There is another part to this, as we have created the numbers of days for the Pairs, I now need to count the number of ID's which have been less than 1 day, 1-2 days, 2-3, 3-4, 4-5 and 5+ etc

 

This would then need to exclude the weekends and also babk holidays, anyway this can be done?

 

Thanks again

Greg_Deckler
Community Champion
Community Champion

@ZR1 Well, there is a NETWORKDAYS function in DAX now that should simplify that.



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
Community Champion
Community Champion

@ZR1 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 ) * 1.

 

Also, if you can post that data as text it would be very helpful in getting to a solution.



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