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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Grouping rows with similar, but not identical time values

Hi Everybody, I've got a query where I group rows which have similar values in several columns, including one coulmn which contains a time value. I need to expand this to also group rows where the time values are within a certain tolerance of one another - for example 15 or 30 minutes. It would also be good to aggregate the min and max time values into new columns.

 

This is a bit more complicated than the standard group by functionality, so I wondered how to achieve this?

 

Many thanks

2 REPLIES 2
amitchandak
Super User
Super User

Can you share sample data and sample output. If possible please share a sample pbix file after removing sensitive information.Thanks.

My Recent Blog -

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi,

 

Thank you for helping  - Here's a simplified example of the input:

Client IDPlanned Start DatePlanned Start TimePlanned Duration
120/07/202009:0030
121/07/202009:0030
122/07/202009:0030
123/07/202009:0030
124/07/202009:0030
125/07/202008:4530
126/07/202009:1530
120/07/202012:0030
121/07/202012:0030
122/07/202012:0030
123/07/202012:0030
124/07/202011:3030
125/07/202012:3030
126/07/202012:3030

 

I can use Table.Group to group all rows which have the same Client ID, Planned Start Time and Planned Duration:

 

= Table.Group(#"Changed Type", {"Client ID", "Planned Start Time", "Planned Duration"}, {{"data", each _, type table [Client ID=nullable number, Planned Start Date=nullable date, Planned Start Time=nullable time, Planned Duration=nullable number]}, {"Count", each Table.RowCount(_), Int64.Type}, {"Median Start Time", each List.Median([Planned Start Time]), type nullable time}})

 

Which gives this output:

 

Client IDPlanned Start TimePlanned DurationdataCountMedian Start Time
109:00:0030table509:00:00
108:45:0030table108:45:00
109:15:0030table109:15:00
112:00:0030table412:00:00
111:30:0030table111:30:00
112:30:0030table212:30:00

 

This is working as expected, but I would like to group rows where the Planned Start Time is within 30 minutes.

This would result in the first three rows being grouped into one: Planned Start Time 09:00, 08:45, 09:15.

The Median Start Time aggregation would then show the median of these times.

 

The last three rows are a bit more complicated since the start times are 12:00, 11:30 and 12:30.

The first two rows (12:00, 11:30) are within 30 minutes of each other, so they could be grouped to form a group of 5 rows.

However, if the 12:00 and 12:30 rows could be grouped that would be even better as it would form a group of 6 rows.

 

I probably need to add a helper column to identify which rows to merge. Any help would be greatly appreciated.

 

Although I've been doing this in power query, it would be fine, or even preferable, to do it in DAX.

 

I've uploaded a sample pbix here:

https://ufile.io/xyd0n3u9

 

Many thanks

 

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.