Forum Discussion
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 specific time stamp, i want a dax formula for "Appearance in past 6 months" where it would count how many time items appear from (6-Jul-22 to 2-Jan-23)
| Items | Week | Week Start Date | Start Count Date Date | Appearance in Past 6 month |
| A | W1 | 2-Jan-23 | 6-Jul-22 | |
| B | W2 | 9-Jan-23 | 13-Jul-22 | |
| C | W3 | 16-Jan-23 | 20-Jul-22 | |
| D | W4 | 23-Jan-23 | 27-Jul-22 |
Thank you so much in advance.
- 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.
2 Replies
- AnonymousNot 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 ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- nhutruongFrequent Visitor
worked like a charm. thank you so much