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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Top N filtered by separate Date and Time table

Hi all,

 

I want to have a measure that calculates the busiest hour of a period. This period could be as long as a day, full week, month, quarter or year. So far I have not been able to get a Top N measure including two filters (date and time). 

 

My datamodel has a separate Date and Time table. So I can't make use of a timestamp.

The Time table is build up as followed:

TimeAM/PMHour LabelHour
00:00A.M.000
01:00A.M.011
02:00A.M.022
03:00A.M.033

 

The Date table is build up as followed (just a regular Date table):

DateYearMonthDay
04/04/20222022April04
03/04/20222022April03
02/04/20222022April02

 

My Fact table is build up as followed:

IDDateTimeCounts
104/04/202211:00212
204/04/202211:00643
303/04/202209:00342
402/04/202209:00231

 

Here I have the following measure in place: "Total Counts = SUM ( Counts )"

The Fact table is ofcource connected with the Date and Time table by a one to many relationship.

 

I want to use the default Card visual of Power BI to display the total Counts of the Peak Hour. Next to this I want to use another Card visual to display the Date and Time of when the Peak Hour have been occurred.

Currently I am using the default Top N filter option in the Filter Panel of Power BI to gather the Top 1 by Hour of my regular "Total Counts" measure. This will give me the Peak Hour, but summed up over the whole period. So for example, If we use the counts and dates of the above tables it will display the following: 11:00 AM - 855.

 

But this is not what I want to display. I want to display the following in my Power BI report: 04/04/2022 - 11:00 AM - 643.

How can I manage to do this with a Measure only? I have experienced with a measure which contains two TOPN functions but this does not work for me. See below:

Top Counts Day and Hour =
CALCULATE (
[Total Counts],
TOPN ( 1, ALL ( 'Date'[Date] ), [Total Counts], DESC ),
TOPN ( 1, ALL ( 'Hour'[Time] ), [Total Counts], DESC )
)



If you need additional information please let me know. 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could try something like

Peak Hour =
var summaryTable = GENERATE( CROSSJOIN( VALUES('Date'[Date]), VALUES('Time'[Time])),
ROW( "@total count", [Total Count])
)
var top1 = TOPN( 1, summaryTable, [@total count], DESC)
return CONCATENATEX( top1, [Date] & " - " & [Time] & " - " & [@total count], ", ")

This will return multiple strings joined by ", " in the case that more than hour has the same high value.

 

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You could try something like

Peak Hour =
var summaryTable = GENERATE( CROSSJOIN( VALUES('Date'[Date]), VALUES('Time'[Time])),
ROW( "@total count", [Total Count])
)
var top1 = TOPN( 1, summaryTable, [@total count], DESC)
return CONCATENATEX( top1, [Date] & " - " & [Time] & " - " & [@total count], ", ")

This will return multiple strings joined by ", " in the case that more than hour has the same high value.

 

Anonymous
Not applicable

Hi @johnt75,

Thank you very much! This works perfect 😀

Helpful resources

Announcements
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.

Top Solution Authors