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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Gosia_Gr
Regular Visitor

DAX for Rolling Count of Records over the time window, with results on a record level

Hi, I'd need some help with DAX that will return Rolling Count of Records over +/-15min time window, including current record with results on a record level.
I’m working in DirectQuery mode. I am not sure which would work better regarding performance - a new Measure or a new Table.
I simplified the table to a minimum.
Let’s call it FactTable. It has a column with IDs: RecordId, they are unique and not in any order. Each record has its Date Time Stamp: column DateTime.
DAX should calculate Rolling Count of Record IDs in a way that when I pull Table visual with RecordID, DateTime and Rolling count - all record level information from FactTable is retained:

Gosia_Gr_0-1732193028242.png

Not sure if needed here, the original model has Date and Time dimension tables linked by DateKey and TimeKey to the FactTable.
Time dimension table has: TimeKey, Time, Minute, Hour. Date dimension table has: DateKey, Date, Month, ect.

 

Thanks in advance.

 

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Thanks for the reply from SachinNandanwar , please allow me to provide another insight:

Hi, @Gosia_Gr 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1732611191467.png

2. Below are the measure I've created for your needs:

Rolling count =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        DATEDIFF ( 'Table'[DateTime], MAX ( 'Table'[DateTime] ), MINUTE ) <= 15
    )
)

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1732611292866.png

If you have any questions, please refer to the attached PBIX file. It is important to note that although my data connection mode is set to Import, it has already been tested in DirectQuery. Since DirectQuery requires a connection to the data source, I uploaded it using the Import method.

vlinyulumsft_2-1732611292867.png

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Hi, @Gosia_Gr 

Thank you for your prompt response.

 

1.Firstly, regarding the query limitation issue, you might consider adjusting the query limits and optimising the queries and data model.

vlinyulumsft_0-1732695811433.png

 

For further details, please refer to:

Set visual query limits in Power BI Desktop - Power BI | Microsoft Learn
Chris Webb's BI Blog: The “Visual Has Exceeded The Available Resources” Error In Power BI
 

2.Secondly, about replicating the DAX I provided within Visual Calculation, based on my practical tests, it is currently not feasible due to the need for filtering. I have not found an effective solution for this yet.

 

For further details, please refer to:

Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn

 

3.Finally, for limiting to just one day, you can directly use the built-in date slicer:

vlinyulumsft_1-1732695811434.png

 

 
Create a relative time slicer or filter in Power BI - Power BI | Microsoft Learn

Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Gosia_Gr
Regular Visitor

Thank you Leroy Lu
Unfortunately, the query reaches the memory limit on my model (1024MB). A View might be my option.

 

I'd have the last question – anyone knows if a similar result can be achieved by writing DAX as a Visual Calculation? The visual could be filtered to one day only, understand it will be the rolling count would be limited to that day only.

Anonymous
Not applicable

Hi, @Gosia_Gr 

Thank you for your prompt response.

 

1.Firstly, regarding the query limitation issue, you might consider adjusting the query limits and optimising the queries and data model.

vlinyulumsft_0-1732695811433.png

 

For further details, please refer to:

Set visual query limits in Power BI Desktop - Power BI | Microsoft Learn
Chris Webb's BI Blog: The “Visual Has Exceeded The Available Resources” Error In Power BI
 

2.Secondly, about replicating the DAX I provided within Visual Calculation, based on my practical tests, it is currently not feasible due to the need for filtering. I have not found an effective solution for this yet.

 

For further details, please refer to:

Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn

 

3.Finally, for limiting to just one day, you can directly use the built-in date slicer:

vlinyulumsft_1-1732695811434.png

 

 
Create a relative time slicer or filter in Power BI - Power BI | Microsoft Learn

Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Leroy Lu, thank you for the comprehensive response and the links to relevant sources with additional info.

Gosia

SachinNandanwar
Super User
Super User

Can you explain how you have a count of 15 & 16 for the first two rows ?



Regards,
Sachin
Check out my Blog

Hi Sachin

Sorry, I forgot to mention. There are more records on 24/11/2024, the table it just a snapshot - the calculation in 1st and 2nd row is counting records before 22/11/2024 22:50.

The whole model has roughly 350 records per day, starting from 2019.

DAX calculation should be continuously rolling, over midnight records as well, i.e. not starting count for each day.

Thanks for your help

Gosia

Anonymous
Not applicable

Thanks for the reply from SachinNandanwar , please allow me to provide another insight:

Hi, @Gosia_Gr 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1732611191467.png

2. Below are the measure I've created for your needs:

Rolling count =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        DATEDIFF ( 'Table'[DateTime], MAX ( 'Table'[DateTime] ), MINUTE ) <= 15
    )
)

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1732611292866.png

If you have any questions, please refer to the attached PBIX file. It is important to note that although my data connection mode is set to Import, it has already been tested in DirectQuery. Since DirectQuery requires a connection to the data source, I uploaded it using the Import method.

vlinyulumsft_2-1732611292867.png

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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