Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
nic2023
Frequent Visitor

Power Query in Excel: Rows with same name, only the latest dated row to keep

Hello lovely people, 

Can I please have some advice on how to set my Query to ONLY keep the latest month's entry, which would be the latest date in Col C. 

e.g. For month of Aug, we only need to keep the yellow highlighted row 6 (04/08/2023), row 1 to 5 can be removed. 

nic2023_0-1692244398250.png

Thank you!

 

1 ACCEPTED SOLUTION
nic2023
Frequent Visitor

Thanks so much! I think I just figured it out: 

We need to sort table 2 times before using Remove duplicates.

 

  1. Sort Column B, if there are more than one Project in Column B;

  2. Make sure your date column is formatted as date and Excel recognize them as date. Otherwise sorting on Date Column won't work; 

  3. Sort the whole table by Date column from Newest to Oldest

  4. Only select  "Project Name" column which holds the criteria to check for duplicates, then use Remove duplicates.

  5. Excel always keeps the first data set of a duplicated row. All consecutive rows can be removed

  6. Done! 

View solution in original post

3 REPLIES 3
nic2023
Frequent Visitor

Thanks so much! I think I just figured it out: 

We need to sort table 2 times before using Remove duplicates.

 

  1. Sort Column B, if there are more than one Project in Column B;

  2. Make sure your date column is formatted as date and Excel recognize them as date. Otherwise sorting on Date Column won't work; 

  3. Sort the whole table by Date column from Newest to Oldest

  4. Only select  "Project Name" column which holds the criteria to check for duplicates, then use Remove duplicates.

  5. Excel always keeps the first data set of a duplicated row. All consecutive rows can be removed

  6. Done! 
abdelaziz0013
New Member

use List.Max()
let
Source = Excel.CurrentWorkbook(),
Table1 = Source{[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Table1,{{"region", type text}, {"project name", type text}, {"date of change", type date}, {"amount", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", let latest = List.Max(#"Changed Type"[date of change]) in each [date of change] = latest)
in
#"Filtered Rows"

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use Date.IsInCurrentMonth to filter your rows. Sample soluton below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcgxwdFbSUXIsLcnPTSzJzM8Dckz0zfSNDIyMQUxTpVgdXKqMLGDKjI1wKjPVh6syt8CpylzfFG6WsTFOZRb6JjBlpma4nWahbwj3gRHQabEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, #"Project Name" = _t, #"Date of Change" = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Region", type text}, {"Project Name", type text}, {"Date of Change", type date}, {"Amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each (Date.IsInCurrentMonth([Date of Change])))
in
    #"Filtered Rows"

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.