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
Nks_Mr
Frequent Visitor

Transforming Table

Hi everybody,

 

does anybody have a clue how to transform the following table from this 

Nks_Mr_0-1733763969194.png

 

to this: 

 

Nks_Mr_1-1733763991261.png

 

Thank you very much in advance!!!

 

BR

 

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @Nks_Mr 
M- code :
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQooys9KTS4BsgyNDAwMwLQpmAJiEyArNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t, #"Budget FY 24" = _t, #"Budget FY 25" = _t, #"Sponsoring FY 24" = _t, #"Sponsoring FY 25" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Type", type text}, {"Budget FY 24", Int64.Type}, {"Budget FY 25", Int64.Type}, {"Sponsoring FY 24", Int64.Type}, {"Sponsoring FY 25", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Type"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.1]), "Attribute.1", "Value", List.Sum),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.2", "Year"}})
in
#"Renamed Columns"

You can also apply the steps with ux of Power query :

Ritaf1983_0-1733766288425.png

Ritaf1983_1-1733766699903.png

 

I attached pbix , so you can follow 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Syk
Super User
Super User

In Power Query, start with your data...

Syk_0-1733766685838.png

Select both budgeting columns and both sponsoring columns and in the Transform tab > unpivot columns.

Syk_1-1733766755642.png

Now under the Add Column tab (not transform) Select the "Attribute" column > Extract > Last Characters > Last 2 will give your your FY number, you can rename this column to FY.

Syk_3-1733766955850.png

Back in the transform tab... Select your "Attribute" column again > Extract > Text before delimiter > when the box pops up just put a space as your delimiter

Syk_4-1733767045631.png

Time to repivot. Select the "Attribute" column again and under Transform > Pivot Column > set the Values column to Value and hit OK 

Syk_5-1733767132258.png

 

 

 

View solution in original post

4 REPLIES 4
Nks_Mr
Frequent Visitor

@Syk @Ritaf1983 

 

Hi both,

 

thank you very much! appreciate it!
I just have a question for a further extension for my model. So basically I used it to transform from this state:


Nks_Mr_0-1734020132096.png

 

into this:

Nks_Mr_1-1734020143567.png


However I have one question: As you can see, I have two zeros for ID 3 in for FY 24. Is it possible to delete the entries with only zeros (best before transforming - maybe to save loading time?) 

Sorry for asking, I'm really a rookie regarding PowerBI.

Thanks in advance!

Hi @Nks_Mr 
Yes, you can create a flag column that checks if the columns values are 0 , and than filter by this column...
But I suppose that the columns will be dynamic, so it is better to filter out zeros after transforming..because you will always have a budget and sponsoring column, no matter how many years of data you have.

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Syk
Super User
Super User

In Power Query, start with your data...

Syk_0-1733766685838.png

Select both budgeting columns and both sponsoring columns and in the Transform tab > unpivot columns.

Syk_1-1733766755642.png

Now under the Add Column tab (not transform) Select the "Attribute" column > Extract > Last Characters > Last 2 will give your your FY number, you can rename this column to FY.

Syk_3-1733766955850.png

Back in the transform tab... Select your "Attribute" column again > Extract > Text before delimiter > when the box pops up just put a space as your delimiter

Syk_4-1733767045631.png

Time to repivot. Select the "Attribute" column again and under Transform > Pivot Column > set the Values column to Value and hit OK 

Syk_5-1733767132258.png

 

 

 

Ritaf1983
Super User
Super User

Hi @Nks_Mr 
M- code :
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQooys9KTS4BsgyNDAwMwLQpmAJiEyArNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t, #"Budget FY 24" = _t, #"Budget FY 25" = _t, #"Sponsoring FY 24" = _t, #"Sponsoring FY 25" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Type", type text}, {"Budget FY 24", Int64.Type}, {"Budget FY 25", Int64.Type}, {"Sponsoring FY 24", Int64.Type}, {"Sponsoring FY 25", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Type"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.1]), "Attribute.1", "Value", List.Sum),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute.2", "Year"}})
in
#"Renamed Columns"

You can also apply the steps with ux of Power query :

Ritaf1983_0-1733766288425.png

Ritaf1983_1-1733766699903.png

 

I attached pbix , so you can follow 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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! Prices go up Feb. 11th.

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.