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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
NickProp28
Post Partisan
Post Partisan

Filter the earliest date based on each ID

Dear Community, 

 

Good Day!

Aprreciate if can provide me some help on Power Query Editor. How can I filter the earliest date in order to overcome the duplicate consolID issues. 

NickProp28_0-1628744795295.png

For example 'C00015706' , the earliest date is 23/1/2019.  And I only need this row. 

 

Here attached with the pbix: https://ufile.io/5c6q50oj

Any help will appreciated!

1 ACCEPTED SOLUTION
Mohammad_Refaei
Solution Specialist
Solution Specialist

In advanced editor replace the code with this:

let
    Source = Excel.Workbook(File.Contents("C:\Users\nikchoo\Desktop\testing123.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Consol ID", type text}, {"ETD", type date}}),
    #"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"ETD", Order.Ascending}})),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"Consol ID"})
in
    #"Removed Duplicates"

 

The idea is simply sorting date in ascending order. Use the Table.Buffer to cache the sorting then remove duplicates.

 

Please check the sample file.

View solution in original post

2 REPLIES 2
Mohammad_Refaei
Solution Specialist
Solution Specialist

In advanced editor replace the code with this:

let
    Source = Excel.Workbook(File.Contents("C:\Users\nikchoo\Desktop\testing123.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Consol ID", type text}, {"ETD", type date}}),
    #"Sorted Rows" = Table.Buffer(Table.Sort(#"Changed Type",{{"ETD", Order.Ascending}})),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"Consol ID"})
in
    #"Removed Duplicates"

 

The idea is simply sorting date in ascending order. Use the Table.Buffer to cache the sorting then remove duplicates.

 

Please check the sample file.

TomMartens
Super User
Super User

Hey @NickProp28 ,

 

personally I'm restricted to downloading files from onedrive, dropbox, or google drive only.

 

Nevertheless, a solution to your requirement should be straightforward.

 

Create a grouping transformation based on the column "Console ID". This article describes how to use this transformation: Grouping or summarizing rows | Microsoft Docs

 

Create a grouping that contains two aggregations

  • Minimum, based on the date column
    This will represent the first date for each id
  • All rows
    This holds all the columns for each row

Then expand the column that holds all the columns, be aware that also the column Console ID is contained. Create a custom column that checks if the column ETD equals the column with the Minimum date return 1 if true, otherwise 0.

Finally, you can filter all the rows that contain 1.

 

Maybe things can be more simple if you just want to remove duplicates, by using the Remove Duplicates transformation:

image.png

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.