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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
suneelkethagani
Frequent Visitor

Need Dates in Same Row for Each Project in Power Query

Hi Guys,

This is my data in Power Query.

Project ID    Status    Status1Date    Status2Date    Status3Date    Status4Date

1                  Status1    1/1/2022      

2                  Status1    2/5/2022

3                  Status2                          5/5/2022

4                  Status3                                                 3/23/2022

5                  Status4                                                                         7/11/2022

1                  Status2                          3/3/2022

1                  Status3                                                   5/6/2022

3                  Status4                                                                          8/3/2022

 

 

I need output like the below...

Project ID    Status    Status1Date    Status2Date    Status3Date    Status4Date

1                  Status1    1/1/2022      3/3/2022         5/6/2022

2                  Status1    2/5/2022

3                  Status2                          5/5/2022                                8/3/2022

4                  Status3                                                 3/23/2022

5                  Status4                                                                         7/11/2022

 

 

Here I have used Group By of "Project ID" and have taken min of all statuses dates. I am getting correct result.

But Sometimes I may be back to the previous status like 

 

Project ID    Status    Status1Date    Status2Date    Status3Date    Status4Date

1                  Status1    1/1/2022      

2                  Status1    2/5/2022

3                  Status2                          5/5/2022

4                  Status3                                                 3/23/2022

5                  Status4                                                                         7/11/2022

1                  Status2                          3/3/2022

1                  Status3                                                   5/6/2022

3                  Status4                                                                          8/3/2022

1                  Status2                           8/8/2022

 

In this case I need this column also need to show in the final table like

Project ID    Status    Status1Date    Status2Date    Status3Date    Status4Date

1                  Status1    1/1/2022      3/3/2022         5/6/2022

1                  Status1     1/1/2022     8/8/2022         5/6/2022

2                  Status1    2/5/2022

3                  Status2                          5/5/2022                                8/3/2022

4                  Status3                                                 3/23/2022

5                  Status4                                                                         7/11/2022

 

 

 

How can I get it in Power Query?

Could you please help me?

 

 

Thanks,

Suneel K.

 

1 REPLY 1
BA_Pete
Super User
Super User

Hi @suneelkethagani ,

 

Paste the following code into a new blank query using Advanced Editor to see the steps I took:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY5bDoAgDATvwjcJfYByF8L9r+HWVLRqUpKW6U46RuKUz0dcUEIiGLxmHkkuLoXaD1c0/gUeV4xXNLoiooV0rRhvaOqthGUv7IcY54c/hD3PwW8nbMGvH39flrcfpAf/PAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Status = _t, Status1Date = _t, Status2Date = _t, Status3Date = _t, Status4Date = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Status", Int64.Type}, {"Status1Date", type date}, {"Status2Date", type date}, {"Status3Date", type date}, {"Status4Date", type date}}),
    remStatusCol = Table.RemoveColumns(chgTypes,{"Status"}),
    groupProjectID = Table.Group(remStatusCol, {"Project ID"}, {{"data", each _, type table [Project ID=nullable number, Status=nullable number, Status1Date=nullable date, Status2Date=nullable date, Status3Date=nullable date, Status4Date=nullable date]}}),
    fillDownNested = Table.TransformColumns(groupProjectID, {"data", each Table.FillDown(_, {"Status1Date", "Status2Date", "Status3Date", "Status4Date"})}),
    fillUpNested = Table.TransformColumns(fillDownNested, {"data", each Table.FillUp(_, {"Status1Date", "Status2Date", "Status3Date", "Status4Date"})}),
    nestedTableDistinct = Table.TransformColumns(fillUpNested, {"data", each Table.Distinct(_)}),
    expandDataCol = Table.ExpandTableColumn(nestedTableDistinct, "data", {"Status1Date", "Status2Date", "Status3Date", "Status4Date"}, {"Status1Date", "Status2Date", "Status3Date", "Status4Date"})
in
    expandDataCol

 

STEP SUMMARY:

remStatusCol = Remove the status column as no longer required

groupProjectID = Group table on [Project ID] and use an 'All Rows' aggregation to create nested project tables

fillDownNested/fillUpNested = just fill all cells in nested tables with dates

nestedTableDistinct = Remove all duplicate rows from nested tables

expandDataCol = Reinstate nested table columns to the main table

 

I get the following output:

BA_Pete_0-1664115106026.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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