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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
GS10
Frequent Visitor

Difference between start date and end date

Hi,

Consider my slicer is march.
case 1:my start time is in february and end time is in march so I want to exclude the start time which is feb and I consider 1st of march as start time and do the difference.
case 2:my start time and end time falls in the slicer I have to find the difference.

case 3:if my end time is blank and start time is in february then I have to find the duration betwen the 1st of march to current time.

GS10_0-1713425041299.png

Regards,

GS

 

2 ACCEPTED SOLUTIONS
ChiragGarg2512
Solution Sage
Solution Sage

For Case 1:

If start date = month(today()) - 1: use TotalMTD function

For Case 2: 

If the start date and end date are both part of the same month simply the difference in the dates can work.

 

For case 3:[Bit unclear]

This should go similarly to case 1 by using TotalMTD from 1st March till date.

View solution in original post

Anonymous
Not applicable

Hi @ChiragGarg2512 , @_AAndrade ,thank you for your replies, I'll add further.

Hi @GS10 ,

The Table data is shown below:

vzhouwenmsft_0-1713862578136.png

Please follow these steps:
1. Use the following DAX expression to create a table

 

Table 2 = CALENDAR(DATE(2024,3,1),DATE(2024,3,31))

 

2.Creating table-to-table relationships

vzhouwenmsft_1-1713862666084.png

3.Use the following DAX expression to create a measure

 

Duration =
VAR _a =
    SELECTEDVALUE ( 'Table'[Start Date] )
VAR _b =
    SELECTEDVALUE ( 'Table'[End Date] )
VAR _c =
    MIN ( 'Table 2'[Date] )
VAR _d =
    MAX ( 'Table 2'[Date] )
VAR _e =
    IF (
        MONTH ( _a ) = 2
            && MONTH ( _b ) = 3,
        DATEDIFF ( DATE ( 2024, 3, 1 ), _b, DAY ),
        IF (
            _a >= _c
                && _b <= _d,
            DATEDIFF ( _a, _b, DAY ),
            IF (
                _b = BLANK ()
                    && CALCULATE ( MONTH ( MAX ( 'Table'[Start Date] ) ) = 2, ALL ( 'Table 2' ) ),
                DATEDIFF (
                    CALCULATE ( MAX ( 'Table'[Start Date] ), ALL ( 'Table 2' ) ),
                    DATE ( 2024, 3, 1 ),
                    DAY
                )
            )
        )
    )
RETURN
    _e

 

4.Final output

vzhouwenmsft_3-1713862848023.png

 

Best Regards,
Wenbin Zhou
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
Anonymous
Not applicable

Hi @ChiragGarg2512 , @_AAndrade ,thank you for your replies, I'll add further.

Hi @GS10 ,

The Table data is shown below:

vzhouwenmsft_0-1713862578136.png

Please follow these steps:
1. Use the following DAX expression to create a table

 

Table 2 = CALENDAR(DATE(2024,3,1),DATE(2024,3,31))

 

2.Creating table-to-table relationships

vzhouwenmsft_1-1713862666084.png

3.Use the following DAX expression to create a measure

 

Duration =
VAR _a =
    SELECTEDVALUE ( 'Table'[Start Date] )
VAR _b =
    SELECTEDVALUE ( 'Table'[End Date] )
VAR _c =
    MIN ( 'Table 2'[Date] )
VAR _d =
    MAX ( 'Table 2'[Date] )
VAR _e =
    IF (
        MONTH ( _a ) = 2
            && MONTH ( _b ) = 3,
        DATEDIFF ( DATE ( 2024, 3, 1 ), _b, DAY ),
        IF (
            _a >= _c
                && _b <= _d,
            DATEDIFF ( _a, _b, DAY ),
            IF (
                _b = BLANK ()
                    && CALCULATE ( MONTH ( MAX ( 'Table'[Start Date] ) ) = 2, ALL ( 'Table 2' ) ),
                DATEDIFF (
                    CALCULATE ( MAX ( 'Table'[Start Date] ), ALL ( 'Table 2' ) ),
                    DATE ( 2024, 3, 1 ),
                    DAY
                )
            )
        )
    )
RETURN
    _e

 

4.Final output

vzhouwenmsft_3-1713862848023.png

 

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

 

ChiragGarg2512
Solution Sage
Solution Sage

For Case 1:

If start date = month(today()) - 1: use TotalMTD function

For Case 2: 

If the start date and end date are both part of the same month simply the difference in the dates can work.

 

For case 3:[Bit unclear]

This should go similarly to case 1 by using TotalMTD from 1st March till date.

_AAndrade
Super User
Super User

Hi @GS10,

I didn't understand your case 3. Could you please explain in more detail what you want on this case?
And what you're looking for is the Month duration like you have on the picture?





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




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.