Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
I am struggling to get a formula to work , where I have a list of ID's and dates . and I want a count ID based the last 7 days
I have added this column to get the 7 day date - 7 days = Today()-7
I then added another column with this formula
Count ID 7 days = (CALCULATE(COUNTA('TU Feed'[ID]),FILTER(ALLSELECTED('TU Feed'),'TU Feed'[ID]=EARLIER('TU Feed'[ID])&&'TU Feed'[departure_date]>='TU Feed'[7 Days])))
But it is not working correctly. I have tried researching this for hours but can't get it to work. any help would be much appreciated
An example of my data in TU Feed
ID - departure_date - time
1 - 20/04/2020 - 01:20
2 - 20/04/2020 -04:50
3 - 20/04/2020 -05:45
1 - 21/04/2020 - 06:45
1 - 21/04/2020 - 12:45 [exclude as duplicate date]
2 - 21/04/2020 - 04:20
2 - 21/04/2020 - 09:20 [exclude as duplicate date]
1 - 22/04/2020 - 10:45
1 - 22/04/2020 - 19:45
2 - 22/04/2020 - 04:20
3 - 22/04/2020 - 09:20
ID 1 - should equal 3
ID 2 - should equal 3
ID 3 - should equal 2
Solved! Go to Solution.
Hi, @Pandadev
Based on your description, today is 4/28/2020. I created data to reproduce your scenario.
Table:
You may create a measure as below.
Count =
var _id = SELECTEDVALUE('Table'[ID])
return
CALCULATE(
DISTINCTCOUNT('Table'[Departure_date]),
FILTER(
ALLSELECTED('Table'),
'Table'[ID] = _id&&
'Table'[Departure_date]>=TODAY()-7&&
'Table'[Departure_date]<=TODAY()
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Pandadev
Based on your description, today is 4/28/2020. I created data to reproduce your scenario.
Table:
You may create a measure as below.
Count =
var _id = SELECTEDVALUE('Table'[ID])
return
CALCULATE(
DISTINCTCOUNT('Table'[Departure_date]),
FILTER(
ALLSELECTED('Table'),
'Table'[ID] = _id&&
'Table'[Departure_date]>=TODAY()-7&&
'Table'[Departure_date]<=TODAY()
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks , for your help , i changed ALLSELECTED to just ALL in your formula , and it now works perfectly.
I think as I was filtering the table to show latest date , the ALL SELECTED method was not working.
Why wouldn't a distinctcount of the date field work?
In my visual IU am filtering by latest date , so it only shows the ltest departure_time per ID , so when I do that it only shows 1 , as I assume it is filtering out all of the previous departure dates. i wanted to be able to show just the latest departure and then show how many in the past 7 days .
The simplest form of the answer is: you have to use ALL() to restore the rows of the table so you can count them when the visuals are just displaying one row.
I wrote:
A measure to get the start date:
Help when you know. Ask when you don't!
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 80 | |
| 38 | |
| 31 | |
| 27 | |
| 27 |