cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
nrowey
Helper I
Helper I

Find latest entry with power query editor

I have a dataset, It has a colume name "Dealno" (Text) and another "Rowlastupdated" (DateTime).

The "Dealno" row is repeted everythime someone makes a change and it is timestamped in "Rowlastupdated"

I am trying to filter out thru Power Query to only show the latest "Dealno" row from the "Rowelastupdated" column.

can this be done in power query to filter the entire table.

Thanks for any help.    

1 ACCEPTED SOLUTION

Hard to tell what you are doing wrong. Even from the UI, the column names don't change for the simple example of two columns -- one with the dealno and one with the date.  When you enter the name of your max date column, it can be whatever you want (even the same as the original date column).

 

If you are expanding a subtable, you may have to edit that step in the Advanced Editor to get rid of the "renaming" which the UI generated step wants to do. That is merely a matter of deleting the optional newcolumnnames argument.

View solution in original post

8 REPLIES 8
v-xinruzhu-msft
Community Support
Community Support

Hi @nrowey 

You can refer to the following code to advanced editor in power query 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIyMDLWN9Q3UorVQREwRRUwQxcw1zcECyTBBEzRBcxAArEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"MaxDate", each List.Max([Column2]), type nullable date}, {"Data", each _, type table [Column1=nullable text, Column2=nullable date]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Column2"}, {"Column2"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Data", "Custom", each if [MaxDate] = [Column2] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Custom] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MaxDate", "Custom"})
in
    #"Removed Columns"

It will not change the column name, you can also see it in the attachments.

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I will try this next time around Thanks

nrowey
Helper I
Helper I

Is there any other way besides a Group By , I already have all the visuals built.

Below is a measure that works but I am trying to get the results in power query........

 

Last Status = var _max = maxx(filter(ALLSELECTED('Query (2)'), 'Query (2)'[dealno] = Max('Query (2)'[dealno])), 'Query (2)'[rowlastupdated])
return
CALCULATE(max('Query (2)'[dealno]), filter(('Query (2)') ,  'Query (2)'[rowlastupdated] =_max))

What am I missing?

 

I don't understand why the method would make a difference. The end result will be the same in PQ.  Please explain.

 

You could also do this by 

  • Add custom column
    • Filtered to return only those rows where
      • Dealno = the Dealno in that column and
      • Rowlastupdate = the latest date
  • Delete the original columns
  • Expand the custom column which will be a List of Tables all meeting the specifications
  • Delete the duplicate rows

But that would take much longer to run and the end result would be the same.

 

Grouping

#"Grouped Rows" = Table.Group(#"Changed Type", {"Dealno"}, {
        {"MaxRowLastUpdated", each List.Max([Rowlastupdated]), type nullable date}
        })

Filtering

 #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        let 
            dn=Table.SelectRows(#"Changed Type", (r)=>r[Dealno]=[Dealno]),
            maxDate=Table.SelectRows(dn, each [Rowlastupdated]=List.Max(dn[Rowlastupdated]))
        in 
            maxDate, 
            type table[Dealno=text, Rowlastupdated=date]),

 

 

The reason I dont want to set up a group-by is all the Visuals are completed. When ever I set up a Group-by the column names all change and I have to start over building visuals etc.?

Or maybe I am doing somthing wrong?

Hard to tell what you are doing wrong. Even from the UI, the column names don't change for the simple example of two columns -- one with the dealno and one with the date.  When you enter the name of your max date column, it can be whatever you want (even the same as the original date column).

 

If you are expanding a subtable, you may have to edit that step in the Advanced Editor to get rid of the "renaming" which the UI generated step wants to do. That is merely a matter of deleting the optional newcolumnnames argument.

I did not reliize I could rename to exsisting column names..  This worked Thanks so much...

 

ronrsnfld
Resident Rockstar
Resident Rockstar

Group by "Dealno" and aggregate by "Max" of "Rowlastupdated"

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors