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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Creating a new table using existing table

I have the below Query Table 

 

Table1

Car_ID

ShiftServiceTypeTimestamp
1011Water Wash; Bubble wash9/1/2021 12:00:00 PM
1021Air Wash9/1/2021 02:10:00 PM
1031Bubble Wash9/1/2021 02:40:00 PM
1012Interior Clean9/1/2021 04:05:00 PM

 

I want to create a new Table in Power Query for Service type and car and respective timestamp, Like below

 

Table2

Service TypeCar NoshiftTimestamp
Water Wash 10119/1/2021 12:00:00 PM
Bubble wash10119/1/2021 12:00:00 PM
Air wash10219/1/2021 02:10:00 PM
Bubble wash10319/1/2021 02:40:00 PM
Interior Clean10129/1/2021 04:05:00 PM

 

Steps I followed:

Created new Query with Servicetype

Changed it to table

Used delimeter as semicolon to split columns. (this created two columns)

Added a custom column ,  = #"Table1"

Expanded to get the CarNo, Shift, Timestamp.

-This is causing the data in second column to disappear.

Is there a better way to get the CarNo, Shift, Timestamp. to table 1?

 

I tried unpivoting and add the columns and didn't work to 

So thought to bring the columns first and then unpivot and that didn't work to.

 

Could anyone help in creating table2?

 

Thanks!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Does this work?

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVNJRAuHwxJLUIoXwxOIMawWn0qSknFSFciAHKGOpb6hvZGBkqGBoZGVgAEQKAb5KsTogzUZQzY6ZEK3Iqg2MrAxRVRtDVUONx6LBBFUDSDHICs88oNsy84sUnHNSE/NQ9JhYGZjC9MQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Car ID" = _t, Service = _t, Type = _t, Timestamp = _t]),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Type", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Type.1", "Type.2"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Car ID", "Service", "Timestamp"}, "Attribute", "Value"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Columns",{"Service", "Car ID", "Value", "Timestamp"})
in
    #"Removed Other Columns"


This:

edhans_0-1631216521319.png

becomes this:

edhans_1-1631216542319.png

You may need to rename the Values column. But it took the multiple possible values in the Type field and made them into their own row by splitting it then unpivoting it.

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

Does this work?

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVNJRAuHwxJLUIoXwxOIMawWn0qSknFSFciAHKGOpb6hvZGBkqGBoZGVgAEQKAb5KsTogzUZQzY6ZEK3Iqg2MrAxRVRtDVUONx6LBBFUDSDHICs88oNsy84sUnHNSE/NQ9JhYGZjC9MQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Car ID" = _t, Service = _t, Type = _t, Timestamp = _t]),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Type", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Type.1", "Type.2"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Car ID", "Service", "Timestamp"}, "Attribute", "Value"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Columns",{"Service", "Car ID", "Value", "Timestamp"})
in
    #"Removed Other Columns"


This:

edhans_0-1631216521319.png

becomes this:

edhans_1-1631216542319.png

You may need to rename the Values column. But it took the multiple possible values in the Type field and made them into their own row by splitting it then unpivoting it.

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors