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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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

v-zhouwen-msft
Community Support
Community Support

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
v-zhouwen-msft
Community Support
Community Support

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
Super User
Super User

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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