Forum Discussion

Yggdrasill's avatar
Yggdrasill
Responsive Resident
6 years ago
Solved

Count dates between two dates within the same column

My table looks like this and in my model has a 1:N relationship with my Calendar Table from Date to Date: Category Date Dimension A 1.1.2020 Cat A 3.2.2020 Dog B 1.1.2019 Cat ...
  • v-alq-msft's avatar
    v-alq-msft
    6 years ago

    Hi, Yggdrasill 

     

    You may modify 'var _date = SELECTEDVALUE('Calendar'[Date])' as 'var _date = MAX('Calendar'[Date])' and make other codes unchanged.

     

    CountValue = 
    var _date = MAX('Calendar'[Date])
    var _status = SELECTEDVALUE(Test[Status])
    var tab = 
    SUMMARIZE(
        ALLSELECTED('Table'),
        'Table'[Case],
        "MaxDate",
        var c = [Case]
        return
        CALCULATE(
            MAX('Table'[Date]),
            FILTER(
                ALLSELECTED('Table'),
                'Table'[Case] =c&&
                'Table'[Date]<=_date
            )
        )
    )
    var newtab = 
    ADDCOLUMNS(
        tab,
        "Status",
        var c = [Case]
        var md = [MaxDate]
        return
        MAXX(
            FILTER(
                ALLSELECTED('Table'),
                'Table'[Case] = c&&
                'Table'[Date] = md
            ),
            [Status to]
        )
    )
    var result = 
    COUNTROWS(
            FILTER(
                newtab,
                [Status] = _status
            )
        )
    return
    IF(
        ISBLANK(result),
        0,
        result
    )

     

     

    Best Regards

    Allan

     

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