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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
StuartSmith
Power Participant
Power Participant

Filter or new table to display latest comment

I have a table called "Export" with various columns including, "ID", "Budget Code", "Comment" & "Comment Date" with a similar layout to below...

Building ID   Budget Code   Comment  Comment  Date
150Blah01/01/2022
160Blah, Blah02/01/2022
230  
240  
320Blah01/01/2022

and so on.

I need to somehow, filter or create a new table to display similar to below...

Building ID   Budget Code  Comment   Comment Date
160Blah, Blah02/01/2022
230  
320Blah01/01/2022

so the criteria needs to be...

If a "Building ID" has multiple rows and comments, keep the row with the most recent comment date.
If a "Building ID" has multiple rows and no comments, keep any row.
If a "Building ID" has 1 row, keep that row, whether there are comments or not

I think that covers it and havent missed anything out.

Thanks in advance

1 ACCEPTED SOLUTION
ribisht17
Super User
Super User

@StuartSmith 

 

Step 1

RANK LATEST = RANKX(FILTER( ALL( Sheet2),Sheet2[Building ID]=max(Sheet2[Building ID])),CALCULATE(min(Sheet2[Comment Date])))
 
Set RANK LATEST to 1
 
Step 2
Max Budget Code Diff = CALCULATE(max(Sheet2[Budget Code]),all(Sheet2),Sheet2[Building ID]=max(Sheet2[Building ID])) - min(Sheet2[Budget Code])
 
Filter this to 0
 
 
ribisht17_0-1651856014397.png
Regards,
Ritesh

View solution in original post

5 REPLIES 5
StuartSmith
Power Participant
Power Participant

Thanks guys, will take a look shortly and get back to you with any questions.

You are welcome !!

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI1ABJOOYkZQMrAUBeIjAyMjJRidSDSZjBpHQWYIiMURUZAIWOQIiBSgIuYoIgYA1lGOOyJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Building ID" = _t, #"Budget Code" = _t, Comment = _t, #"Comment  Date" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Building ID"}, {{"All", each Table.Max(_,"Comment  Date")}}),
    #"Expanded All" = Table.ExpandRecordColumn(#"Grouped Rows", "All", {"Budget Code", "Comment", "Comment  Date"}, {"Budget Code", "Comment", "Comment  Date"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded All",{{"Comment  Date", type date}})
in
    #"Changed Type"

Hope this helps.

Untitled.png


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

Hope this satisfies your requirement, if yes, kindly mark the answer as correct so that it can help others as well

 

Regards,
Ritesh
Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 
ribisht17
Super User
Super User

@StuartSmith 

 

Step 1

RANK LATEST = RANKX(FILTER( ALL( Sheet2),Sheet2[Building ID]=max(Sheet2[Building ID])),CALCULATE(min(Sheet2[Comment Date])))
 
Set RANK LATEST to 1
 
Step 2
Max Budget Code Diff = CALCULATE(max(Sheet2[Budget Code]),all(Sheet2),Sheet2[Building ID]=max(Sheet2[Building ID])) - min(Sheet2[Budget Code])
 
Filter this to 0
 
 
ribisht17_0-1651856014397.png
Regards,
Ritesh

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.