Forum Discussion
Rolling count based on two criteria
Dear community,
I was hoping you could help out with the following question, I have a dataset whicht contains information about persons and dates whenever they have some duty to forfill (marked with X).
I would like to calculate the following count column:
- For each person there needs to be a count of X'es for every row, but it needs to be a rolling count which looks 28 days back
I was hoping somebody could help me out with this calculation? If anymore info is needed please let me know
| Person | Date (ddmmyyyy) | Duty | Count |
Sander | 1-1-2022 | X | 1 |
| Sander | 2-1-2022 | 1 | |
| Sander | 3-1-2022 | X | 2 |
| Sander | 4-1-2022 | X | 3 |
| Sander | 5-1-2022 | 3 | |
| Mark | 1-1-2022 | X | 1 |
| Mark | 2-1-2022 | X | 2 |
| Mark | 3-1-2022 | 2 | |
| Mark | 4-1-2022 | 2 | |
| Mark | 5-1-2022 | 2 | |
| Mark | 6-1-2022 | 2 |
Hi Lumegu ,
If you want to use custom column ,try the below:
test3 = var qqq=countx( FILTER ( 'Table', 'Table'[Person] = EARLIER ( 'Table'[Person] ) && 'Table'[Duty] = "X" && 'Table'[Date (ddmmyyyy)] >= TODAY () - 28 && 'Table'[Date (ddmmyyyy)] <= TODAY () ),0) return if(qqq=BLANK(),0,qqq)Output:
And if you want to use measure:
test = IF(MAX('Table'[Duty])="X"&&MAX('Table'[Date (ddmmyyyy)])>=TODAY()-28 &&MAX('Table'[Date (ddmmyyyy)])<=TODAY(),1,0)test2 = SUMX('Table','Table'[test])Output:
Did I answer your question? Mark my post as a solution!
Best RegardsLucien
3 Replies
- v-luwang-msft
Community Support
Hi Lumegu ,
If you want to use custom column ,try the below:
test3 = var qqq=countx( FILTER ( 'Table', 'Table'[Person] = EARLIER ( 'Table'[Person] ) && 'Table'[Duty] = "X" && 'Table'[Date (ddmmyyyy)] >= TODAY () - 28 && 'Table'[Date (ddmmyyyy)] <= TODAY () ),0) return if(qqq=BLANK(),0,qqq)Output:
And if you want to use measure:
test = IF(MAX('Table'[Duty])="X"&&MAX('Table'[Date (ddmmyyyy)])>=TODAY()-28 &&MAX('Table'[Date (ddmmyyyy)])<=TODAY(),1,0)test2 = SUMX('Table','Table'[test])Output:
Did I answer your question? Mark my post as a solution!
Best RegardsLucien
- amitchandak
Super User
Lumegu , try a new column like
new column =
var _date = [Date] -28
return
countx(filter(Table, [Person] = earlier([Person])&& [Date] <= earlier([Date]) && [Date] >= _date),[Person])- LumeguFrequent Visitor
Thanks for the quick reply, however I only want to count if there is a X in column duty. How could this be added to the calculation?