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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sellersmd
Frequent Visitor

How to match activity times against a schedule in Power Query

Hello,

 

I have two tables I am working with.

 

One is a daily 'schedule' of times when certain activities should occur and includes the activity name, start time, and end time. In this table, activities are repeated with multiple start and end times, and start and end times can be re-used across activities. This table represents all possible times that activities can occur.

 

ActivityStartEnd
A12:00:00 AM1:00:00 AM
A2:30:00 AM3:30:00 AM
A6:00:00 PM7:00:00 PM
B12:00:00 AM1:00:00 AM
B6:00:00 PM7:00:00 PM
C2:30:00 AM3:30:00 AM
C6:00:00 PM7:00:00 PM

 

The second table is a list of activities along with date and what time the activity started. Activities are started multiple times per day:

 

ActivityDateStart Time
B01-01-2312:27:00 AM
C01-01-233:44:00 AM
A01-01-2312:56:00 AM
B01-02-236:03:00 PM
C01-02-236:15:00 PM
A01-03-233:15:00 AM

 

Ultimately, I'd like to create a new table that summarizes the information as follows:

 

DateActivityTotal CountCount (On Time)Count (Early)Count (Late)
1-1-23A    
1-1-23B    
1-1-23C    
1-2-23A    
1-2-23B    
1-2-23C    
1-3-23A    
1-3-23B    
1-3-23C    

 

The Count (On Time) would represent the daily count of activities that started between the start and end time, the Count (Early) would represent the daily count of activities that started up to 30 minutes prior to the start time, and the Count (Late) would represent the daily count of activities that started up to 30 minutes after the end time.

 

I can easily create the new table with Date, Activity, and Total Count using SUMMARIZE(). I am struggling to create new columns for Count (On Time), Count (Early), and Count(Late).

 

Any help with the appropriate DAX to get these figured would be greatly appreciated!

 

Thanks in advance.

 

Matt

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sellersmd ,

 

I think the first table is the schedule table, and the second table is the table of the actual start time, right?

Here's my solultion. It's recommended to complete it in Power Query.

1.You can merge the Actual table with the Schedule table. Reference: Merge Queries

vstephenmsft_0-1674111497497.png

vstephenmsft_1-1674111565142.png

 

2.Expand the tables in the Schedule column.

vstephenmsft_2-1674111598176.png

vstephenmsft_3-1674111605095.png

3.Create a custom column to get the On Time, Early and Late. Refernce: Add a custom column - Power Query | Microsoft Learn

vstephenmsft_4-1674111641730.png

vstephenmsft_5-1674111681824.png

 

4.Remove the rows contains null.

vstephenmsft_6-1674111701347.png

Click OK.

vstephenmsft_7-1674111710638.png

5.Remove the unneeded columns and add a custom column with 1.

vstephenmsft_9-1674111981044.png

6.Pivot the Custom column to get the countings.

vstephenmsft_10-1674112017762.png

vstephenmsft_11-1674112028416.png

Pivot columns (Power Query) - Microsoft Support

 

 

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @sellersmd ,

 

I think the first table is the schedule table, and the second table is the table of the actual start time, right?

Here's my solultion. It's recommended to complete it in Power Query.

1.You can merge the Actual table with the Schedule table. Reference: Merge Queries

vstephenmsft_0-1674111497497.png

vstephenmsft_1-1674111565142.png

 

2.Expand the tables in the Schedule column.

vstephenmsft_2-1674111598176.png

vstephenmsft_3-1674111605095.png

3.Create a custom column to get the On Time, Early and Late. Refernce: Add a custom column - Power Query | Microsoft Learn

vstephenmsft_4-1674111641730.png

vstephenmsft_5-1674111681824.png

 

4.Remove the rows contains null.

vstephenmsft_6-1674111701347.png

Click OK.

vstephenmsft_7-1674111710638.png

5.Remove the unneeded columns and add a custom column with 1.

vstephenmsft_9-1674111981044.png

6.Pivot the Custom column to get the countings.

vstephenmsft_10-1674112017762.png

vstephenmsft_11-1674112028416.png

Pivot columns (Power Query) - Microsoft Support

 

 

 

Best Regards,

Stephen Tao

 

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

Hi Stephen,

 

Elegant solution and easy to follow. I was unaware that when you merged queries you could do a many-to-one match - that was exactly what I needed! Thanks for your help. 

KeyurPatel14
Responsive Resident
Responsive Resident

Hii @sellersmd ,
Can you please provide full output so that I can help you quicker??

 

Hello @KeyurPatel14!

 

Thank you for taking the time to reply. Here are dropbox links to a test schedule and test activity data. I hope thats what you were looking for by full output. If not, please clarify and I will provide whatever is needed!

 

Test Schedule 

Test Activity Data 

 

Thank you in advance!

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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