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
tvalente
Helper I
Helper I

Returning the date/time from the maximum count of rows

Hi All,

 

I want to write a DAX expression to return the time from the maximum count of rows.

 

So as per below it would be 17:00.

 

Capture.PNG

 

My best attempt. This is returning the wrong answer at 19:00 currently

 

MaxTimeCount = CALCULATE (
MAX ( 'Bike & Pedestrian Data'[TimeExtract (bins)] ),
FILTER ( 'Bike & Pedestrian Data', 'Bike & Pedestrian Data'[TimeExtract (bins)] = MAX ( 'Bike & Pedestrian Data'[TimeExtract (bins)] ) )
)
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@tvalente,

 

Try these measures. The concept is to rank [Count Rows] (a measure) in a virtual table, and then filter the virtual table for the top-ranked row.

 

Count Rows = COUNT ( 'Bike & Pedestrian Data'[ID] )

MaxTimeCount = 
VAR vBaseTable =
    ADDCOLUMNS (
        SUMMARIZE (
            'Bike & Pedestrian Data',
            'Bike & Pedestrian Data'[TimeExtract (bins)],
            'Bike & Pedestrian Data'[Transport Type]
        ),
        "@CountRows", [Count Rows]
    )
VAR vRankTable =
    ADDCOLUMNS (
        vBaseTable,
        "@Rank", RANKX ( vBaseTable, [@CountRows],, DESC, DENSE )
    )
VAR vTopRank =
    FILTER ( vRankTable, [@Rank] = 1 )
VAR vResult =
    MAXX ( vTopRank, 'Bike & Pedestrian Data'[TimeExtract (bins)] )
RETURN
    vResult

 

DataInsights_0-1630507121236.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
tvalente
Helper I
Helper I

Worked a charm thank you very much

DataInsights
Super User
Super User

@tvalente,

 

Try these measures. The concept is to rank [Count Rows] (a measure) in a virtual table, and then filter the virtual table for the top-ranked row.

 

Count Rows = COUNT ( 'Bike & Pedestrian Data'[ID] )

MaxTimeCount = 
VAR vBaseTable =
    ADDCOLUMNS (
        SUMMARIZE (
            'Bike & Pedestrian Data',
            'Bike & Pedestrian Data'[TimeExtract (bins)],
            'Bike & Pedestrian Data'[Transport Type]
        ),
        "@CountRows", [Count Rows]
    )
VAR vRankTable =
    ADDCOLUMNS (
        vBaseTable,
        "@Rank", RANKX ( vBaseTable, [@CountRows],, DESC, DENSE )
    )
VAR vTopRank =
    FILTER ( vRankTable, [@Rank] = 1 )
VAR vResult =
    MAXX ( vTopRank, 'Bike & Pedestrian Data'[TimeExtract (bins)] )
RETURN
    vResult

 

DataInsights_0-1630507121236.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.