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
AndreasB
Regular Visitor

Count Records Between Start date/time and End date/time (for every second of the day(s))

Hi,
I need some help with a formula in DAX for a measure.

data:

_idStart Date/TimeEnd Date/Time
63c13320c47798de09659e2c13.01.2023 10:19:0813.01.2023 10:19:31
63c13320c47798de09659d0913.01.2023 10:20:1813.01.2023 10:20:52
63c13320c47798de09659d1f13.01.2023 10:23:2813.01.2023 10:24:54
63c13320c47798de09659d2013.01.2023 10:19:2013.01.2023 10:20:10
63c13320c47798de09659d3513.01.2023 10:18:3513.01.2023 10:19:15
63c13320c47798de09659db913.01.2023 10:18:2213.01.2023 10:19:54
63c13320c47798de09659de813.01.2023 10:19:3013.01.2023 10:20:00
63c13320c47798de09659e0913.01.2023 10:20:0113.01.2023 10:20:26
63c13320c47798de09659cbc13.01.2023 10:20:4013.01.2023 10:26:45


And I have a date/time table (similar to a date table but with a record per second instead of a record per day):
[D/Ts]

date/time
13.01.2023 10:19:16
13.01.2023 10:19:17
13.01.2023 10:19:18
13.01.2023 10:19:19
13.01.2023 10:19:20
13.01.2023 10:19:21
13.01.2023 10:19:22
13.01.2023 10:19:23
13.01.2023 10:19:24

 

What I'd need is a measure for each [D/Ts].'date/time' that count([data].'id') where [D/Ts].'date/time' >= [data].'Start date/time' AND [D/Ts].'date/time' <= [data].'End date/time':

date/time required result
13.01.2023 10:19:162
13.01.2023 10:19:172
13.01.2023 10:19:182
13.01.2023 10:19:192
13.01.2023 10:19:203
13.01.2023 10:19:213
13.01.2023 10:19:223
13.01.2023 10:19:233
13.01.2023 10:19:243


Thanks in advance for any help getting this solved.

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewMeasure=VAR _Second=MAX('D/Ts'[date/time]) RETURN COUNTROWS(FILTER(Data,Data[Start Date/Time]<=_Second&&Data[End Date/Time]>=_Second))

View solution in original post

2 REPLIES 2
AndreasB
Regular Visitor

Thanks a lot @wdx223_Daniel  - this was exactly what I was trying to do. 

wdx223_Daniel
Super User
Super User

NewMeasure=VAR _Second=MAX('D/Ts'[date/time]) RETURN COUNTROWS(FILTER(Data,Data[Start Date/Time]<=_Second&&Data[End Date/Time]>=_Second))

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.