top of page

Power Query : Get the last / max record from a subset

  • Marek Vavrovic
  • May 3, 2022
  • 2 min read

Sample data:


I have a table where 1 Order Number has multiple record in that. I want to retrieve just the most recent one.

ree

1. Group by Order Number. Operation : All Rows



ree

I need the last recent record by Order Date for each Order Number.

ree

This is my last step in Power Query, now I have to delele everything from each until number]


ree

I have end up with a code like this, and I am going to use a table function Table.Max () needs a table name and its atttribut as parameters (in this case).

ree

each Table.Max(_ , "Order Date") ...for each row in my Table.Group() or groupped table retrieve the maximal value for "Order Date" attribute.

ree

Expand the Subtable and pick records you want to return.

ree

Final Table:


ree

Or you can convert your records into a list by adding the attribute name on the end of the query. You will get a list and you can covert this list into a table. Or you can retrive just on specific record from the entire table by specifying its value using {3-1} ...this means I want to retrieve 3rd record only from order number 200.


ree

I have Order number 202, 3rd record. On the left - top corner there is an option to convert this into a table.

ree

ree

To convert this table into a tabular format use Pivot transformation


ree

And I have retrived one specific row from the table.

ree

[attribe] ...if you want to access the attributes

{1-1} ...if you need to access the records. This is for the first record. You can also use {0}


Let's say I need to extract the highlithed text for any reason



ree

  1. Click on the Fx to add a custom step

  2. Specify column name and row number

ree

you can convert the number to table or list

ree

And I have retrieved just one specific value from the entire table and can use it in ...reporting.

ree

Comments


Subscribe Form

©2020 by MaVa Analytics. Proudly created with Wix.com

bottom of page