Power Query , get record with last data and 1 more criteria

Wishmaster89

Board Regular
Joined
Jan 10, 2022
Messages
77
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Hi All

I've got some data which has duplicate ID's(uln). I want to get the last row based on the max date and the standard description. I know how to get the last date by doing group by ID and then getting the max date(col B) for each but how do i add in additional criteria please?

So , ID 2 should have a record for music and history ect.



Min ifs.xlsx
ABCDEFGHIJKL
1ULNMaxDateAll1.ULNAll1.Academic_YearAll1.Completion_StatusAll1.Learning_OutcomeAll1.Framework_NameAll1.Standard_CodeAll1.Standard_DescriptionAll1.Learning_Start_Date2All1.Learning_Start_DateAll1.Learning_End_Date3
2242320898604/11/2021 00:002423208986201719English60English2017050202/05/2017 00:0015/10/2021 00:00
3242320898604/11/2021 00:002423208986201821English60English01/09/1989 00:0004/11/2021 00:00
4242320898604/11/2021 00:002423208986202021Geography60Geography02/05/2017 00:0007/05/2021 00:00
5219/10/2022 00:002201719Music60Music2017050202/05/2017 00:0009/08/2020 00:00
6219/10/2022 00:002201821Music60Music10/03/1989 00:0011/09/2021 00:00
7219/10/2022 00:002202021History60History02/05/2017 00:0019/10/2022 00:00
8310/10/2022 00:003201019Maths60Maths2017050202/05/2010 00:0022/10/2012 00:00
9310/10/2022 00:003201321IT60IT10/03/2013 00:0004/05/2015 00:00
10310/10/2022 00:003202221Music60Music02/05/2022 00:0010/10/2022 00:00
example_24


M language ( with data filtered by max date)

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="example_24"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ULN", Int64.Type}, {"Academic_Year", Int64.Type}, {"Completion_Status", Int64.Type}, {"Learning_Outcome", Int64.Type}, {"Framework_Name", type text}, {"Standard_Code", Int64.Type}, {"Standard_Description", type text}, {"Learning_Start_Date2", Int64.Type}, {"Learning_Start_Date", type datetime}, {"Learning_End_Date3", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ULN"}, {{"MaxDate", each List.Max([Learning_End_Date3]), type date}, {"All1", each _, type table [ULN=nullable number, Academic_Year=nullable number, Completion_Status=nullable number, Learning_Outcome=nullable number, Framework_Name=nullable text, Standard_Code=nullable number, Standard_Description=nullable text, Learning_Start_Date2=nullable number, Learning_Start_Date=nullable datetime, Learning_End_Date3=nullable datetime]}}),
    #"Expanded All1" = Table.ExpandTableColumn(#"Grouped Rows", "All1", {"ULN", "Academic_Year", "Completion_Status", "Learning_Outcome", "Framework_Name", "Standard_Code", "Standard_Description", "Learning_Start_Date2", "Learning_Start_Date", "Learning_End_Date3"}, {"All1.ULN", "All1.Academic_Year", "All1.Completion_Status", "All1.Learning_Outcome", "All1.Framework_Name", "All1.Standard_Code", "All1.Standard_Description", "All1.Learning_Start_Date2", "All1.Learning_Start_Date", "All1.Learning_End_Date3"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded All1", each true),
    #"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"MaxDate", type datetime}}),
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type1", each ([MaxDate]=[All1.Learning_End_Date3] ))
in
    #"Filtered Rows1"
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Is this the output you're looking for?

WM89
ABCDEFGHIJKL
1ULNMaxDateAll1.Standard_DescriptionAll1.ULNAll1.Academic_YearAll1.Completion_StatusAll1.Learning_OutcomeAll1.Framework_NameAll1.Standard_CodeAll1.Learning_Start_Date2All1.Learning_Start_DateAll1.Learning_End_Date3
2242320898611/4/2021English2423208986201821English609/1/198911/4/2021
3242320898611/4/2021Geography2423208986202021Geography605/2/20175/7/2021
4210/19/2022Music2201821Music603/10/19899/11/2021
5210/19/2022History2202021History605/2/201710/19/2022
6310/10/2022Maths3201019Maths60201705025/2/201010/22/2012
7310/10/2022IT3201321IT603/10/20135/4/2015
8310/10/2022Music3202221Music605/2/202210/10/2022
Table1 (2)


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"ULN", "MaxDate", "All1.Standard_Description"}, {{"Data", each _, type table [ULN=number, MaxDate=datetime, All1.ULN=number, All1.Academic_Year=number, All1.Completion_Status=number, All1.Learning_Outcome=number, All1.Framework_Name=text, All1.Standard_Code=number, All1.Standard_Description=text, All1.Learning_Start_Date2=nullable number, All1.Learning_Start_Date=number, All1.Learning_End_Date3=number]}}),
    SR = Table.TransformColumns(Group,{{"Data", each Table.PromoteHeaders(Table.Transpose(Record.ToTable(Table.Max(_,"All1.Academic_Year"))))}}),
    Expand = Table.ExpandTableColumn(SR, "Data", {"All1.ULN", "All1.Academic_Year", "All1.Completion_Status", "All1.Learning_Outcome", "All1.Framework_Name", "All1.Standard_Code", "All1.Learning_Start_Date2", "All1.Learning_Start_Date", "All1.Learning_End_Date3"}, {"All1.ULN", "All1.Academic_Year", "All1.Completion_Status", "All1.Learning_Outcome", "All1.Framework_Name", "All1.Standard_Code", "All1.Learning_Start_Date2", "All1.Learning_Start_Date", "All1.Learning_End_Date3"})
in
    Expand
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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