Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Count values between dates

Hi all! 

I need a DAX measure to count items between dates, example:

 

itemstartend
A01/01/202203/01/2022
B05/01/202210/01/2022
C04/01/202206/01/2022
D02/01/202208/01/2022
E07/01/202209/01/2022

 

Result with DAX:

 

calendar[date]quantity itemref item
01/01/20221A
02/01/20222A, D
03/01/20222A, D
04/01/20222C, D
05/01/20223B, C, D
06/01/20223B, C, D
07/01/20223B, D, E
08/01/20223B, D, E
09/01/20222B, E
10/01/20221B

Obs: column "ref item" in second table only illustrative, not consider

 

Can you help?

  • Hi, Anonymous 

     

    You can try the following methods.

    Table:

    calendar = CALENDAR(MIN('Table'[start]),MAX('Table'[end]))

    Measure:

    quantity item =
    CALCULATE (
        COUNT ( 'Table'[item] ),
        FILTER (
            ALL ( 'Table' ),
            [start] <= SELECTEDVALUE ( 'calendar'[Date] )
                && [end] >= SELECTEDVALUE ( 'calendar'[Date] )
        )
    )
    

    Is this the result you expect?

     

    Best Regards,

    Community Support Team _Charlotte

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

4 Replies