Power Query Challenge - Find Latest Value and filter out the rest

Nothnless

Board Regular
Joined
Apr 28, 2016
Messages
142
Hi, I'm Using Get&Transform in Excel which is equivalent to Power Query in Power BI. It even uses the same M language.

Is there a way to use the query to get a result that displays the following?

If there are duplicate errors then keep the latest error of those duplicates and filter out the rest.

Original table:
TimeNameError
1:00JohnY
2:00JohnY
3:00SmithN
4:00DaveY
3:00JohnY

Result:
TimeNameError
3:00SmithN
4:00DaveY
3:00JohnY

In this case the duplicate John's with errors were removed except for the John at 3:00

Thank you,
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Take your data into PowerQuery ('From Table' in the 'Get & Transform' tab of the Data ribbon.
Group the data by Name and Error and select Max [Time] as the aggregation.
Close and Load.

HTH
 
Upvote 0
edit: didn't refresh thread :devilish:

time.png

Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Time", type time}, {"Name", type text}, {"Error", type text}}),
    Group = Table.Group(Type, {"Name", "Error"}, {{"Time", each List.Max([Time]), type time}}),
    Result = Table.ReorderColumns(Group,{"Time", "Name", "Error"})
in
    Result
 
Upvote 0
Take your data into PowerQuery ('From Table' in the 'Get & Transform' tab of the Data ribbon.
Group the data by Name and Error and select Max [Time] as the aggregation.
Close and Load.

HTH

This is AWESOME and so easy, I didn't think about the aggregation. Thanks!
 
Upvote 0
Take your data into PowerQuery ('From Table' in the 'Get & Transform' tab of the Data ribbon.
Group the data by Name and Error and select Max [Time] as the aggregation.
Close and Load.

HTH

One more thin though, this is just obviously sample data. I have other columns in my real data, how do I display those other columns? If I expand the All Columns option it unrolls the results.
 
Upvote 0
At the group by stage add another aggregation column, called 'Other Rows' as shown here:
1580400091605.png


After clicking OK, you'll see another column with 'Table's in. When you expand those you'll have the choice of which columns you wish to see, plus you'll have the new column 'Max'.

Hopefully that will be sufficient.
 
Upvote 0
so show representative example

Here you go:
As you can see the Error Code may be different but I still want to show Error Code 3333 John at 3:00. If this possible?

TimeNameErrorLast NameError Code
1:00JohnYDoe
1111​
2:00JohnYDoe
6666​
3:00SmithNCane
3333​
4:00DaveYCoop
4444​
3:00JohnYDoe
3333​
 
Upvote 0
where's the error code come from? Previously you were talking about time, now its codes!
 
Upvote 0
where's the error code come from? Previously you were talking about time, now its codes!

Because I only care about the latest time value as far as the grouping is concerned but I still need to show all the columns in the table. So yes getting the John and 3:00 is exactly the result I need but I would still need to see the last name column, the Error Code column and the 30 other columns next to those.
 
Upvote 0

Forum statistics

Threads
1,223,810
Messages
6,174,763
Members
452,582
Latest member
ruby9c

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