PowerPivot- Return The Max Of Column

bravo1563

New Member
Joined
Dec 25, 2013
Messages
20
Hello
Below is sample of my table that I have in a PowerPivot model. What I'm trying to do is return the most recent "Code" associated with the particular "OrderNbr". I need this calculation as a calculated column because I'm going to use this calculated column as a filter. It gets tricky because I have some orders with the same date and unfortunately it's only at a Date level, my data doesn't include a time as well. Can this be done? Any help would be great!

Please note my data isn't sorted like the below, it is sorted randomly.
[TABLE="width: 277"]
<colgroup><col><col><col span="2"></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 277"]
<colgroup><col><col><col span="2"></colgroup><tbody>[TR]
[TD]Date[/TD]
[TD="align: center"]OrderNbr[/TD]
[TD]Value[/TD]
[TD]Code[/TD]
[/TR]
[TR]
[TD]1/28/2016[/TD]
[TD="align: center"]39441[/TD]
[TD]$49.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD]1/22/2016[/TD]
[TD="align: center"]39989[/TD]
[TD]$38.00[/TD]
[TD]RES[/TD]
[/TR]
[TR]
[TD]1/28/2016[/TD]
[TD="align: center"]48357[/TD]
[TD]$48.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD="align: center"]1/21/2016[/TD]
[TD="align: center"]50087[/TD]
[TD]$28.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD]1/23/2016[/TD]
[TD="align: center"]50087[/TD]
[TD]$49.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD="align: right"]1/27/2016 [/TD]
[TD="align: center"]50087[/TD]
[TD]$2.00[/TD]
[TD]RES[/TD]
[/TR]
[TR]
[TD]1/27/2016[/TD]
[TD="align: center"]50087[/TD]
[TD]$9.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD]1/26/2016[/TD]
[TD="align: center"]56163[/TD]
[TD]$43.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD]1/22/2016[/TD]
[TD="align: center"]57622[/TD]
[TD]$6.00[/TD]
[TD]MAN[/TD]
[/TR]
[TR]
[TD]1/25/2016[/TD]
[TD="align: center"]62544[/TD]
[TD]$17.00[/TD]
[TD]MAN[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi bravo1563,

If you want a DAX calculated column, I would use something like this:

=
CALCULATE (
CALCULATE (
// Break ties between Codes on the same date by taking the 'max' Code alphabetically
LASTNONBLANK (
Data
Code:
,[/FONT][/INDENT]
[INDENT=3][FONT=courier new]        0[/FONT][/INDENT]
[INDENT=2][FONT=courier new]    ),[/FONT][/INDENT]
[INDENT=2][FONT=courier new]LASTDATE ( Data[Date] )[/FONT][/INDENT]
[INDENT][FONT=courier new]),[/FONT][/INDENT]
[INDENT][FONT=courier new]ALLEXCEPT ( Data, Data[OrderNbr] )[/FONT][/INDENT]
[FONT=courier new])[/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,766
Messages
6,174,373
Members
452,560
Latest member
Turbos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top