# Find datetime of Max Output (when more than one record can have max output)

Hello All. I am creating an exercise tracking app (thanks Covid!). I am trying to figure out how to create a virtual column to contain the latest date/time when my highest output occurred. The data is in a single table and the columns of interest are [Date Of Workout] and [Total Output].

I created a [Max Output] VC that gets me the MAX OUTPUT from the records of interest:
`MAX(SELECT(Workouts[Total Output],AND([Fitness Discipline]="Cycling",[Total Output]>0)))`

I am now trying to create a VC for [Date of Max Workout], which means I need to find the latest workout record from those where the max output occurred. Soâ€¦ was hoping to SELECT all the records where [Total Output] = [Max Output], and then select only the latest workout record from that subset.

Can anyone suggest the easiest formula to do this?

One approach may be to have a two step

1. Find the row with the max workout with a VC called say [MaxTotalOutput]

MAXROW(â€śWorkoutsâ€ť , â€śTotal Outputâ€ť, AND([Fitness Discipline]=â€śCyclingâ€ť,[Total Output]>0))

1. The date then can be found in the VC [Date of Max Workout] with an expression

``                   [MaxTotalOutput].[Date Of Workout]``
2 Likes

Thanks for the suggestion. Not sure if this solves the case when more than 1 record can have the same max output (eg: last Tue and this Wed both has the same Output)?

Example:
date output
Mar2. 200
Mar5. 180
Mar7. 200

I want to determine the â€ślatest max output dateâ€ť which would be Mar7 in this case.

Thank you. Got it. I believe in that case you may need to use ORDERBY() in place of MAXROW() in that case for the first VC. Something like below

INDEX(ORDERBY( FILTER(â€śWorkoutsâ€ť , AND([Fitness Discipline]=â€śCyclingâ€ť,[Total Output]>0)), [Total Output], TRUE, [Date of Workout], TRUE), 1)

Then the second column computation remains same.

Edit: Based the above expression on the example under â€śRow with maximum valueâ€ť in the help article on ORDERBY()

3 Likes

Thanks!! Will take a look later. Didnâ€™t want to get more complicated than needed and had not checked out OrderBy. Appreciated

2 Likes

You are welcome @Mike . Nice to see you posting in the community again after some gap.

3 Likes

I agreed with the approach shown by @Suvrutt_Gurjar
Better to use Orderby expression.

You can make that field to Ref to pull the values from other column from that as well. Getting more flexible to do more.

When it comes to orderby expression, make sure to pass the ID values , otherwise we see unexpected result out of it.

3 Likes

Thanks for the insights. And yesâ€¦ I have been away for quite some time and trying to catch back up to the latest evolutions with my favorite tool! Great to see the community is still active and vibrant.

Will play around a bit with Orderby as that should solve it. Thanks again for the inputs and for taking the time to share knowledge.

3 Likes