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
Adn1
New Member

Calculate the highest date value for people with the same ID.

Hi All,

 

I want to create a new column in my table.

This column must calculate the highest date from the "END_DATE" column for lines of peoples that have the same "ID".


This is an example of how the table should work:

NAME       ID      END_DATE           New Column (Highest Date)
Ana 124/01/2023 24/01/2023
Gustav 101/01/2023 24/01/2023
Louis 3510/02/2022 10/02/2022
Gabe 3510/01/2022 10/02/2022



1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Adn1 ,

 

How about this:

 

Before:

tackytechtom_1-1683601775122.png

 

After:

tackytechtom_2-1683601791658.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough). The idea is to join the query from after the grouping (calculating MaxDate per ID) with the original query before the grouping:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLVNJRUjAEEkYm+gaG+kYGRsZKsTrRSu6lxSWJZTBJoAyypE9+aWYxSM7YFEgaGugbGIEkjSA6E5NSUeQMoXKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [NAME = _t, ID = _t, END_DATE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"NAME", type text}, {"ID", Int64.Type}, {"END_DATE", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MaxDate", each List.Max([END_DATE]), type nullable date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"MaxDate"}, {"MaxDate"})
in
    #"Expanded Grouped Rows"

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
tackytechtom
Super User
Super User

Hi @Adn1 ,

 

How about this:

 

Before:

tackytechtom_1-1683601775122.png

 

After:

tackytechtom_2-1683601791658.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough). The idea is to join the query from after the grouping (calculating MaxDate per ID) with the original query before the grouping:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLVNJRUjAEEkYm+gaG+kYGRsZKsTrRSu6lxSWJZTBJoAyypE9+aWYxSM7YFEgaGugbGIEkjSA6E5NSUeQMoXKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [NAME = _t, ID = _t, END_DATE = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"NAME", type text}, {"ID", Int64.Type}, {"END_DATE", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MaxDate", each List.Max([END_DATE]), type nullable date}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"MaxDate"}, {"MaxDate"})
in
    #"Expanded Grouped Rows"

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

thanks!

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.

Top Solution Authors
Top Kudoed Authors