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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors