Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Count Difference between dates broken out by month

Is there a way to calculate the difference between two dates but break them out by months?

 

My table example is:

IDDate StartDate EndDuration
12312/11/201816/11/20185
12302/01/201907/01/20196
100303/06/201907/08/201966

 

This count works fine for short dates within the same month but I'm hoping to get a month count between the start and end dates?

 

So I'm hoping to have some sort of breakout/ split to show:

IDJuneJulyAugust
100328317

 

Thanks.

  • Anonymous  firstly, you need create a date table, which have no relationship with your fact table. then try this code

    DaysCount :=
    SUMX (
        Table1,
        VAR sd = Table1[Date Start]
        VAR ed = Table1[Date End]
        RETURN
            CALCULATE (
                COUNT ( 'Calendar'[Date] ),
                KEEPFILTERS ( DATESBETWEEN ( 'Calendar'[Date], sd, ed ) )
            )
    )

     

     

2 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    Anonymous  firstly, you need create a date table, which have no relationship with your fact table. then try this code

    DaysCount :=
    SUMX (
        Table1,
        VAR sd = Table1[Date Start]
        VAR ed = Table1[Date End]
        RETURN
            CALCULATE (
                COUNT ( 'Calendar'[Date] ),
                KEEPFILTERS ( DATESBETWEEN ( 'Calendar'[Date], sd, ed ) )
            )
    )