Forum Discussion
arolon2
6 years agoFrequent Visitor
How to count an ID over a specific timeframe
I have a table (Roster) that includes IDs number and dates. What I am trying to do is count is the amount of occurances of that ID from the date listed the row until a week later.
| UniqueID | DateDay | What I want |
| 1 | 1/1/2020 | 2 |
| 1 | 1/3/2020 | 2 |
| 1 | 1/8/2020 | 1 |
| 1 | 2/14/2020 | 1 |
| 2 | 1/1/2020 | 1 |
| 2 | 2/1/2020 | 1 |
I tried the follwing but was unsuccesful. How should I be handling the second part of the filter to get be the correct timeframe?
IDCOUNT =
VAR CurrentID = Roster[UniqueID]
VAR CurrentWeek = Roster[DateDay]
VAR NextWeek = DATEADD(Roster[DateDay],7,DAY)
RETURN
COUNTROWS(
FILTER(
Roster,
CurrentID = Roster[UniqueID] &&
(CurrentWeek >= Roster[DateDay] || CurrentWeek <= NextWeek)
)
)
Hi arolon2
DATEADD() is a very tricky function https://docs.microsoft.com/en-us/dax/dateadd-function-dax
The result table includes only dates that exist in the dates column.create a column
IDCOUNT = VAR CurrentID = Roster[UniqueID] VAR CurrentWeek = Roster[DateDay] VAR NextWeek = Roster[DateDay] + 7 RETURN COUNTROWS( FILTER( Roster, CurrentID = Roster[UniqueID] && CurrentWeek <= Roster[DateDay] && Roster[DateDay] < NextWeek ) )
1 Reply
- az38
Community Champion
Hi arolon2
DATEADD() is a very tricky function https://docs.microsoft.com/en-us/dax/dateadd-function-dax
The result table includes only dates that exist in the dates column.create a column
IDCOUNT = VAR CurrentID = Roster[UniqueID] VAR CurrentWeek = Roster[DateDay] VAR NextWeek = Roster[DateDay] + 7 RETURN COUNTROWS( FILTER( Roster, CurrentID = Roster[UniqueID] && CurrentWeek <= Roster[DateDay] && Roster[DateDay] < NextWeek ) )