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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors