Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hi Everyone,
I am very new to Power BI and attempting to teach myself how to use it. I have some very poorly layed out data that I wish to change the format of. Can anyone walk me through how to do this? I could use a python script to ammend to output a cleaner version of the data but I was hoping to instead learn more Power BI functionality.
Here is the format of the origonal data.
Algeria
Country risk assessments :
C
Business climate assessments :
C
Angola
Country risk assessments :
C
Business climate assessments :
D
Argentina
Country risk assessments :
D
Business climate assessments :
B
And I want to data to move into columns and look like the following:
Country | Country risk assessments | Business climate assessments |
Algeria | C | C
Angola | C | D
Argentina | D | B
So there are a number of problems to fix here.
1) The multiple "titles" of "Country risk assessments"and "Business climate assessments"
and
2) Realiging the rows to columns which can't just be a transpose as they are sequential like headings
Any help would be much appreaciated
Solved! Go to Solution.
@LAH start a new blank query and copy this M code, follow these steps in your table, tweak the solution as you see fit.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxJTy3KTFSK1YlWcs4vzSspqlQoyizOVkgsLk4tLs5NzSspVrCCSINJp9LizDygjEJyTmZuYkkqToWOeen5OdQ12AVicFE6UCwzjyizXYg120kpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Group" = Table.AddColumn(#"Added Index", "Group", each [Index]-Number.Mod([Index],5), Int64.Type),
#"Added Column Order" = Table.AddColumn(#"Added Group", "Column Order", each Number.Mod([Index],5), Int64.Type),
#"Removed Index" = Table.RemoveColumns(#"Added Column Order",{"Index"}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Index", {{"Column Order", type text}}, "en-CA"), List.Distinct(Table.TransformColumnTypes(#"Removed Index", {{"Column Order", type text}}, "en-CA")[#"Column Order"]), "Column Order", "Data"),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"0", "Country"}, {"2", "Country risk assessments"}, {"4", "Business climate assessments"}}),
#"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns",{"Country", "Country risk assessments", "Business climate assessments"})
in
#"Removed Other Columns"
Output:
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@LAH start a new blank query and copy this M code, follow these steps in your table, tweak the solution as you see fit.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxJTy3KTFSK1YlWcs4vzSspqlQoyizOVkgsLk4tLs5NzSspVrCCSINJp9LizDygjEJyTmZuYkkqToWOeen5OdQ12AVicFE6UCwzjyizXYg120kpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Group" = Table.AddColumn(#"Added Index", "Group", each [Index]-Number.Mod([Index],5), Int64.Type),
#"Added Column Order" = Table.AddColumn(#"Added Group", "Column Order", each Number.Mod([Index],5), Int64.Type),
#"Removed Index" = Table.RemoveColumns(#"Added Column Order",{"Index"}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Index", {{"Column Order", type text}}, "en-CA"), List.Distinct(Table.TransformColumnTypes(#"Removed Index", {{"Column Order", type text}}, "en-CA")[#"Column Order"]), "Column Order", "Data"),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"0", "Country"}, {"2", "Country risk assessments"}, {"4", "Business climate assessments"}}),
#"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns",{"Country", "Country risk assessments", "Business climate assessments"})
in
#"Removed Other Columns"
Output:
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.