# Calculate MAX Sum by Product and by Time

I have a table with a list of Product[Product Name], Product[Count] and Product[Time am/pm].
Needing help to write Dax for the MAX Product Name by Product Count and the Product Time the MAX Count occurred.
Thanks!

please provide your power bi file and expected results.

Itâ€™s confidential data and itâ€™s too large. Can you perhaps write an example?

did you do a search within the forum, youtube?

Yep, I have received help from the forum before which has been most helpful. Iâ€™ve attached a test file. As I mentioned in my first post the metrics needed. ThanksTest Max Count and Time.pbix (69.7 KB)

Hi @LisaKBI1129,

Note that you havenâ€™t marked your Date table as a date table.
Give this a go.

`Total Count = SUM( 'HighwayTraffic Table'[Traffic Count] )`
.

``````Max Value =
VAR _MAX = [Total Count]
VAR _Result =
CALCULATE( MAX( 'HighwayTraffic Table'[Highway] ),
FILTER( ALLSELECTED( 'HighwayTraffic Table' ),
_Max
)
)
RETURN
_Result
``````

.

``````Max Time =
VAR _MAX = [Total Count]
VAR _Value = [Max Value]
VAR _Result =
CALCULATE( MIN( 'HighwayTraffic Table'[Time] ),
FILTER( ALLSELECTED( 'HighwayTraffic Table' ),
[Highway] = _Value &&
_MAX
)
)
RETURN
_Result
``````

I hope this is helpful

1 Like

Unfortunately, this doesnâ€™t give me the Time in which the MAX Count occurred and which Highway.

â€śName of Highwayâ€ť â€śMax Countâ€ť â€śTime of Max Countâ€ť (peak time of travel)

What outcome do you expect?

I table with the 3 Highways listed, the Max Count per highway, and a single Timestamp in which the Max Count occurred. 3 Rows and 3 Columns

Hi @LisaKBI1129,

Okay thanks, give this a go.

``````Max Highway =
VAR _MAX = [Total Count]
VAR _Result =
CALCULATE( MAX( 'HighwayTraffic Table'[Highway] ),
FILTER( 'HighwayTraffic Table',
_Max
)
)
RETURN
_Result
``````

.

``````Max Count =
CALCULATE( [Total Count],
TOPN( 1,
SUMMARIZE( 'HighwayTraffic Table', 'HighwayTraffic Table'[Highway], 'HighwayTraffic Table'[Time] ),
"@Total", [Total Count]
),  [@Total]
)
)
``````

.

``````Max Time =
CALCULATE( MAX( 'HighwayTraffic Table'[Time] ),
TOPN( 1,