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
baalmeida
New Member

How to convert double headers in columns

Dear all, 

The file from the data base comes with the date on the 1st row than the fact in 2nd row. The first column is the Exchange rate level and the others columns are the values for each fact by each exchange level (Please see the image bellow). I need to convert this model into 4 columns (Date, Exchange Rate, fact and values), whats is the best way to do it?  

 

baalmeida_0-1624039655312.png

 

Thanks!

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @baalmeida ,

 

Please use Transpose and Merge column function in the query editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ11DVT0kEwY3WilUKDXYBCviG+JfkliTlgISM9U6CQqZmpqSlEjbEeWJsxCIIFTPTMQQJmQDWWSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Transposed Table" = Table.Transpose(#"Changed Type"),
    #"Merged Columns" = Table.CombineColumns(#"Transposed Table",{"Column1", "Column2"},Combiner.CombineTextByDelimiter("|", QuoteStyle.None),"Merged"),
    #"Transposed Table1" = Table.Transpose(#"Merged Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"2021-1-6|USD", type number}, {"2021-1-6|MTMtotal", Int64.Type}})
in
    #"Changed Type1"

Vlianlmsft_0-1624427170147.pngVlianlmsft_1-1624427178863.png

 

 

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

View solution in original post

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @baalmeida ,

 

Please use Transpose and Merge column function in the query editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ11DVT0kEwY3WilUKDXYBCviG+JfkliTlgISM9U6CQqZmpqSlEjbEeWJsxCIIFTPTMQQJmQDWWSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Transposed Table" = Table.Transpose(#"Changed Type"),
    #"Merged Columns" = Table.CombineColumns(#"Transposed Table",{"Column1", "Column2"},Combiner.CombineTextByDelimiter("|", QuoteStyle.None),"Merged"),
    #"Transposed Table1" = Table.Transpose(#"Merged Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"2021-1-6|USD", type number}, {"2021-1-6|MTMtotal", Int64.Type}})
in
    #"Changed Type1"

Vlianlmsft_0-1624427170147.pngVlianlmsft_1-1624427178863.png

 

 

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

Ashish_Mathur
Super User
Super User

Hi,

See if my solution here helps - Rearrange a multi heading dataset into a single heading one which is Pivot ready.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.