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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Simon_
New Member

For each subset in data find latest date

Hi folks,

I want to analyse a table with Power Query of dates of work packages for different projects. I need to create a new table containing a list of all projects and their finish date. A project is considered finished when all work packages are finished, the finished date is the latest date of the work packages. Different projects have varying numbers of work packages.

The input looks like this:

Project IDWorkpackageWorkpackage finished
P1A01.08.2023
P1B02.08.2023
P1C03.08.2023
P2A02.07.2023
P2B12.07.2023
P3A 
P3B02.08.2023
P3C04.08.2023
P3D 

The output I want to generate should look like this:

Project IDProject finished
P103.08.2023
P212.07.2023
P3 

 

So the logic is: For each Project ID, check if all work packages are finished, if yes find and return latest date, else return null.

 

I would really really appreciate any help. I think I could code this in C but I'm totally lost in Power Query M.

Thank you!

Simon

3 REPLIES 3
ThxAlot
Super User
Super User

finished.pbix

 

Way more concise to use DAX

ThxAlot_0-1691676543992.png

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Manoj_Nair
Solution Supplier
Solution Supplier

@Simon_- Please check this out, copy the M code in your advanced editor, use the same field name. Let me know if this works. If this fix your problem, please tick this a solution and a thumps up.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjBU0lFyBGIDQz0DCz0jAyNjpVgdqLgTSNwIU9wZJG6MKm4EMweo3hxNHGSOIZq4MVS9AoKLzTpjmHUmmOIuQKwUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Workpackage = _t, #"Workpackage finished" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", type text}, {"Workpackage", type text}, {"Workpackage finished", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Project ID"}, {{"MaxDate", each List.Max([Workpackage finished]), type nullable date}})
in
    #"Grouped Rows"

 

 

Vijay_A_Verma
Super User
Super User

Sample code below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjBU0lFyBGIjAyNjXQMLXQNDpVgdqLgTsrgRQtwZWdwYIm6EYo45XL0RijnmuoZQcWOoegQPm23G6LaZIMRdwLpjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Workpackage = _t, #"Workpackage finished" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", type text}, {"Workpackage", type text}, {"Workpackage finished", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Project ID"}, {{"Project finished", each if List.Contains(_[Workpackage finished],null) then null else List.Max(_[Workpackage finished])}})[[Project ID], [Project finished]]
in
    #"Grouped Rows"

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors