Forum Discussion
nhutruong
3 years agoFrequent Visitor
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...
- Anonymous3 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 ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
3 years agoNot applicable
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.
nhutruong
3 years agoFrequent Visitor
worked like a charm. thank you so much