Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
arolon2
Frequent 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.

 

UniqueIDDateDayWhat I want
11/1/20202
11/3/20202
11/8/20201
12/14/20201
21/1/20201
22/1/20201

 

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)
)
)

 

1 ACCEPTED SOLUTION
az38
Community Champion
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
     )
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

1 REPLY 1
az38
Community Champion
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
     )
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.