Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Count dates between two dates excluding dynamic days

Hi community, I've this table, and I want to return the count of days between two dates and exclude all "False" days (monday, or tuesday, or wednesday...).   Example: id DataInicio DataFim...
  • v-deddai1-msft's avatar
    v-deddai1-msft
    6 years ago

    Hi Anonymous ,

     

    Please refer to the following measure:

     

     

    Measure =
    VAR days =
        DATEDIFF ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ), DAY ) + 1
    VAR selected_dates =
        ADDCOLUMNS (
            GENERATESERIES ( MAX ( 'Table'[DataInicio] ), MAX ( 'Table'[DataFim] ) ),
            "Weekday", WEEKDAY ( [Value], 3 )
        )
    VAR mcount =
        IF (
            MAX ( 'Table'[Monday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 0 ) ),
            0
        )
    VAR tcount =
        IF (
            MAX ( 'Table'[Tuesday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 1 ) ),
            0
        )
    VAR wcount =
        IF (
            MAX ( 'Table'[Wednesday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 2 ) ),
            0
        )
    VAR Tucount =
        IF (
            MAX ( 'Table'[thursday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 3 ) ),
            0
        )
    VAR fcount =
        IF (
            MAX ( 'Table'[friday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 4 ) ),
            0
        )
    VAR sacount =
        IF (
            MAX ( 'Table'[saturday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 5 ) ),
            0
        )
    VAR suncount =
        IF (
            MAX ( 'Table'[sunday] ) = "False",
            COUNTROWS ( FILTER ( selected_dates, [Weekday] = 6 ) ),
            0
        )
    RETURN
        ( days - ( mcount + tcount + wcount + Tucount + fcount + sacount + suncount ) )

     

     

     

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

     

    Best Regards,

    Dedmon Dai