Forum Discussion

nhutruong's avatar
nhutruong
Frequent Visitor
3 years ago
Solved

DAX command for count records within a time range

Hi everyone,   I want to find a dax command to return the result which looks something like the table below (Table 1). I have another master table where each items appear multiple time with a speci...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi nhutruong ,

     

    I suggest you to try this code to create a measure.

    Appearance in Past 6 month =
    CALCULATE (
        COUNT ( 'MasterTable'[Item] ),
        FILTER (
            'MasterTable',
            'MasterTable'[Item] = MAX ( 'Table1'[Item] )
                && 'MasterTable'[Timestamp] >= MAX ( 'Table1'[Start Count Date] )
                && 'MasterTable'[Timestamp] <= MAX ( 'Table1'[Week Start Date] )
        )
    )

    Or calculated column:

    Appearance in Past 6 month =
    CALCULATE (
        COUNT ( 'MasterTable'[Item] ),
        FILTER (
            'MasterTable',
            'MasterTable'[Item] = EARLIER ( 'Table1'[Item] )
                && 'MasterTable'[Timestamp] >= EARLIER ( 'Table1'[Start Count Date] )
                && 'MasterTable'[Timestamp] <= EARLIER ( 'Table1'[Week Start Date] )
        )
    )

     

    Best Regards,
    Rico Zhou

     

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