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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ninos-shiba
Resolver I
Resolver I

How to transform data that's all in one table but need to create a column based on each break?

I have a file that looks like this:

Category 1  
 Calls OfferedCalls Handled
4/3/201734002571
4/4/201712781130
4/5/201723972390
4/6/201726782672
4/7/201716871675
4/10/201720342012
Category 2  
4/3/20174341231
4/4/20177658495
4/5/20176568465
4/6/20179822313
4/7/20178785656
4/10/20176665949

 

I want to transform this table into something like this:

DateCalls OfferedCalls HandledCategory
4/3/2017340025711
4/4/2017127811301
4/5/2017239723901
4/6/2017267826721
4/7/2017168716751
4/10/2017203420121
4/3/201743412312
4/4/201776584952
4/5/201765684652
4/6/201798223132
4/7/201787856562
4/10/201766659492

 

How would I be able to transform that?

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @ninos-shiba 

This should be done in the query editor. Place the following M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY+xDsMgDER/BTFHCjbYwJylWz8gyhApSZeoldIu/fsSBxjoAIf1OLgbRz3Mn/XxOr4KdKdVWnrqRjkM876/1X3b1mNd6nybn8ue5vOW622PBnyC1hmTBMlDRq4gQB9OAWsyooLQxiwFcUUsriSYka8PcrjEU0Zgqs1YJwKXrdbDXE+1yZ0YAO1fcM+U9uAitbmZWAhTGzsGlEJg29RB+tBpbUMzy0/RRT1NPw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Column1], "Category") then [Column1] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column2] <> " ")),
    #"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{" ", type date}, {"Calls Offered", Int64.Type}, {"Calls Handled", Int64.Type}, {"Category 1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{" ", "Date"}, {"Category 1", "Handeld category"}})
in
    #"Renamed Columns"

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @ninos-shiba 

This should be done in the query editor. Place the following M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY+xDsMgDER/BTFHCjbYwJylWz8gyhApSZeoldIu/fsSBxjoAIf1OLgbRz3Mn/XxOr4KdKdVWnrqRjkM876/1X3b1mNd6nybn8ue5vOW622PBnyC1hmTBMlDRq4gQB9OAWsyooLQxiwFcUUsriSYka8PcrjEU0Zgqs1YJwKXrdbDXE+1yZ0YAO1fcM+U9uAitbmZWAhTGzsGlEJg29RB+tBpbUMzy0/RRT1NPw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Column1], "Category") then [Column1] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column2] <> " ")),
    #"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{" ", type date}, {"Calls Offered", Int64.Type}, {"Calls Handled", Int64.Type}, {"Category 1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{" ", "Date"}, {"Category 1", "Handeld category"}})
in
    #"Renamed Columns"

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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