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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jug
Frequent Visitor

Select rows with the most recent date without groupby

Hi, I would like to know if someone could help me with the following question:

 

I need to filter only the columns with the most recent date (and smaller than today, if possible), filtering the maximum for each ID and keeping the information from the rest of the table for that row. I tried with group by, but it's a lot of data and it doesn't load, I tried to filter and delete duplicates, but I'm using directquery so it's not possible to delete data.

 

When using the filter when modifying the table, it returns this formula:


= Table.SelectRows(TABLE1, let latest = List.Max(TABLE1[Date]) in each [Date] = latest)

would it not be possible to edit it  and mention that I would like it to return all rows, selecting only the most recent/maximum of each ID?

 

Example

Jug_0-1674255906270.png

 

Should result in this:

 

Jug_1-1674255931886.png

 

Thanks!

 

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Address", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Date] < DateTime.Date(DateTime.LocalNow())),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"ID"}, {{"Count", each Table.Max(_,"Date")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Date", "Address"}, {"Date", "Address"})
in
    #"Expanded Count"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I replaced all the field names with the real ones in the table correctly, the problem is that after the "IN" if I put only  #"Expanded Count" it does not work, I believe it needs to mention the table too

After in, you always have to specify the name of the last step.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Unfortunately, it does not work because it has a group function and this is not supported with DirectQuery.

amitchandak
Super User
Super User

@Jug , refer my blog for the same

 

https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I was able to use this filter of the most recent date only in the dashboard, but I need to have information from different data tables in the same table.
For example, showing the most recent address from the address table and the customer name from the client table, they have already been related by the client code, but I need the filter so that the table does not bring all the registered addresses of the same client.

I would need to bring information from two tables and your formula includes only one. Would it be possible to include fields from another table?

Unfortunately I could not use these ideas, because I'm trying to do this filter in the modification of the query, so then I can create a relationship with another table, so create a measure does not help me in this, from what I saw, it does not appear as a column in the table. Thus, I can't use.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.