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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KatiS
Frequent Visitor

Create a table using columns from another table

Hi everyone, 

 

I am a Power BI novice and need help with creating a new table using columns from another table. The original table is very large, with a lot of other columns, but I summarised the columns that I need to bring it into a new table as per the image below.  There are multiple projects that have start and end dates for the different project phases. I would need to create a column with the phases associated with the various dates, and then display start and end dates as per those phases. So I need to combine the various date columns into just two: start and end dates and those dates to be associtated with the phase. Hope this makes sense. 

 

This seems rather complex to me, and woud appreciate some help in creeting this. 

 

Image (7).jpg

 

1 ACCEPTED SOLUTION

Result

dufoq3_0-1711431030752.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlFwVNJRMgRiI30DY30jAyMTEF/fwBTGNkbmGJrqG5hhcMyVYnUQBjqBDINKm8PVGusbGsA5RvpAhLALzDaF2mUI5BgbKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, No = _t, #"Bid Start Date" = _t, #"Bid End Date" = _t, #"Secured Date" = _t, #"Project Start date" = _t, #"Project end date" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Name", "No"}, "Phase", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Phase", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Phase", "Date Type"}),
    TransformedDateType = Table.TransformColumns(#"Split Column by Delimiter", {{"Date Type", each if Text.Lower(_) = "date" then "Start Date" else Text.Proper(_), type text}}),
    #"Pivoted Column" = Table.Pivot(TransformedDateType, List.Distinct(TransformedDateType[#"Date Type"]), "Date Type", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null, each [Start Date], Replacer.ReplaceValue, {"End Date"})
in
    #"Replaced Value"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Hi @KatiS, provide sample data as table so we can copy paste, and expected result based on sample data. Thank you.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

KatiS
Frequent Visitor

Name NoBid Start Date Bid End Date Secured DateProject Start date Project end date 
Project A12/03/20241/05/202431/05/202415/06/202415/06/2027
Project B215/07/202413/10/202412/12/20241/02/202531/01/2031
       
Convert to       
Name NoPhase Start Date End Date  
Project A1Bid2/03/20241/05/2024  
Project A1Secured31/05/202431/05/2024  
Project A1Project15/06/202415/06/2027  
Project B2Bid15/07/202413/10/2024  
Project B2Secured12/12/202412/12/2024  
Project B2Project1/02/202531/01/2031  

Result

dufoq3_0-1711431030752.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlFwVNJRMgRiI30DY30jAyMTEF/fwBTGNkbmGJrqG5hhcMyVYnUQBjqBDINKm8PVGusbGsA5RvpAhLALzDaF2mUI5BgbKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, No = _t, #"Bid Start Date" = _t, #"Bid End Date" = _t, #"Secured Date" = _t, #"Project Start date" = _t, #"Project end date" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Name", "No"}, "Phase", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Phase", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Phase", "Date Type"}),
    TransformedDateType = Table.TransformColumns(#"Split Column by Delimiter", {{"Date Type", each if Text.Lower(_) = "date" then "Start Date" else Text.Proper(_), type text}}),
    #"Pivoted Column" = Table.Pivot(TransformedDateType, List.Distinct(TransformedDateType[#"Date Type"]), "Date Type", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null, each [Start Date], Replacer.ReplaceValue, {"End Date"})
in
    #"Replaced Value"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

KatiS
Frequent Visitor

Thank you. It looks perfect! exactly what I am after. I am bit lost, however, as to what the code in the "Source =...."  means and what sections in the code do I need to adjust at my end to connect to my table. My original table is called "Data". How do I link what you have in your Source code to my "Data" table?

Hi, have you read note below my posts?

 

BTW. The source code of my query is automatic generated. I used Enter Data button in PQ user interface. If you enter data like this - it will generate similar code.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

KatiS
Frequent Visitor

Sorry I have completely missed that. I thought it was just part of the forum generic txt. Makes sense. Easy. Thank you. 

You're welcome.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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