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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
jps_HHH
Helper II
Helper II

help to transform a table on Powerquerry

I have transformed a table from excel file (throught powerquerry) to a unique table to be used in PBI. 

At the moment the table contains:

Column 1            Column 2      Column 3           Column 4      Column 5            Column 6      Column 7           Column 8 
fiscal year 25       Site 1            April                    50 sells         fiscar year 24       Site 2             April                      46 sells  
fiscal year 25       Site 1            May                    20 sells          fiscar year 24       Site 2             May                      33 sells  
fiscal year 25       Site 1            June                    15 sells          fiscar year 24       Site 2             June                     55 sells  
fiscal year 25       Site 1             July                     40 sells         fiscar year 24       Site 2              July                     23 sells  
fiscal year 25       Site 1             August               21 sells          fiscar year 24        Site 2            August                 23 sells
fiscal year 25       Site 1              September        24 sells           fiscar year 24      Site 2            September           29 sells

and I want to combine "column 1 with column 5" and "column 2 and column 6" and "column 3 with column 7" and "column 4 with column 8"  , like : 

Column 1            Column 2      Column 3           Column 4    
fiscal year 25       Site 1            April                    50 sells         
fiscal year 25       Site 1            May                    20 sells         
fiscal year 25       Site 1            June                    15 sells          
fiscal year 25       Site 1             July                     40 sells          
fiscal year 25       Site 1             August               21 sells         
fiscar year 24       Site 2             April                  46 sells  
fiscar year 24       Site 2             May                   33 sells  
fiscar year 24       Site 2             June                  55 sells  
fiscar year 24       Site 2              July                  23 sells  
fiscar year 24        Site 2            August              23 sells

Could you help me ?

1 ACCEPTED SOLUTION

I need further assistance since I've made more changes at the file. So It is not enough to copy the code and paste it (because it will clean all previous steps done by me).

View solution in original post

13 REPLIES 13
v-achippa
Community Support
Community Support

Hi @jps_HHH,

 

Thank you for reaching out to Microsoft Fabric Community.

 

To combine the columns and get the expected output, please follow below steps:

  • Open Power bi desktop and load the table.
  • Open the Power Query Editor and go to the Advanced Editor
    vachippa_0-1746707650494.png

     

  • Replace the existig code with the below code and click on Done:

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSsssTk7MUahMTSxSMDJV0lEKzixJVTAEMhwLijJzgLSpgUJxak5OMZAJVlwEVWwCU2yEpNjEDKo4Vgef2b6JlUDSiBiTIUqNjYky16s0LxVIGZoSYTBUrakpkSbngNxhQoyToWqNiHOzY2l6aXEJSL0hMQENV02c6cGpBSWpuUmpRSAtJkRYgKLBEmZHLAA=", BinaryEncoding.Base64), Compression.Deflate)),
    let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t, #"Column 2" = _t, #"Column 3" = _t, #"Column 4" = _t, #"Column 5" = _t, #"Column 6" = _t, #"Column 7" = _t, #"Column 8" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, type text})),
    FirstHalf = Table.SelectColumns(#"Changed Type", {"Column 1", "Column 2", "Column 3", "Column 4"}),
    SecondHalf = Table.SelectColumns(#"Changed Type", {"Column 5", "Column 6", "Column 7", "Column 8"}),
    RenamedSecond = Table.RenameColumns(SecondHalf, {{"Column 5", "Column 1"}, {"Column 6", "Column 2"}, {"Column 7", "Column 3"}, {"Column 8", "Column 4"}}),
    Combined = Table.Combine({FirstHalf, RenamedSecond}) in Combined

 

And the output will be like below:

vachippa_1-1746708056294.png

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

 

Hi @jps_HHH 

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution I have provided for the issue worked? or let us know if you need any further assistance.
If my response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

I need further assistance since I've made more changes at the file. So It is not enough to copy the code and paste it (because it will clean all previous steps done by me).

Hi @jps_HHH,

 

Is your issue resolved? What changes have you made and what exact assistance you need from our side? please question completely what is the issue and explain in detail

 

Thanks and regards,

Anjan Kumar Chippa

Hi @jps_HHH 

 

As we haven’t heard back from you, we wanted to kindly follow up to check Is your issue resolved 
If any response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

jps_HHH
Helper II
Helper II

I didnt understand how to manage this code. 
In the link below there is similar file in excel that I need to tranform it 

https://limewire.com/d/o7fqo#8FhhUIkPZr 

@jps_HHH , Have a look at this file. Is this what you are looking for? 
https://docs.google.com/spreadsheets/d/1bUhF-MBUL661hxi4soJP8G4sWDdSc1tF/export?format=xlsx&ouid=104...

Sundar Rajagopalan

yes, that is what i'looking for

SundarRaj
Super User
Super User

Hi @jps_HHH , another solution for you to look at. Thanks. Also, what would I mention is, that if you can possibly provide static column names to it rather than Column1, it would be great since it would allow you to split automatically without manually typing in the number 4. It'll pick up the distinct count of columns and use that. Here, I have given certain names to the columns for you reference.

SundarRaj_0-1746521542719.png

SundarRaj_1-1746521597117.png

Here's the code:

let
Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}}),
ColNames = List.Distinct ( Record.ToList( #"Changed Type"{0} ) ),
Number = List.Count ( ColNames ),
Splitting = List.Split ( Table.ToColumns ( #"Changed Type" ) , Number ),
Table = List.Transform ( Splitting , each Table.PromoteHeaders ( Table.FromColumns ( _ ) ) ),
Combined = Table.Combine ( Table )
in
Combined

 

Sundar Rajagopalan
wdx223_Daniel
Super User
Super User

NewStep=#table(List.FirstN(Table.ColumnNames(YourTable),4),List.TransformMany(Table.ToRows(YourTable),each List.Split(_,4),(x,y)=>y))

Omid_Motamedise
Super User
Super User

Hi @jps_HHH 

 

copy the following code and past it into the advanceeditor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSsssTk7MqUxNLDIyVdJRCs4sSTUE0o4FRZk5QNrUoDg1J6cYyAIrLAIrNIEqNEJSaGIGURirg9NM38RKIGlEyESIMmNjguZ5lealAilDUwIGQtWZmhJhYg7IbhNCToSqMyLsRsfS9NLiEpBaQ0IBCVcJMzUWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),
    #"Transposed Table" = Table.Transpose(Source),
    Custom1 = Table.Combine(List.Transform(Table.Split(#"Transposed Table",4),Table.Transpose))
in
    Custom1
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
slorin
Super User
Super User

Hi @jps_HHH 

= Table.Combine(
List.Transform(
Table.ToRows(Your_Source),
each Table.FromRows(List.Split(_,4))))

or

= Table.FromRows(
List.Combine(
Table.ToList(
Your_Source,
each List.Split(_,4))))

 

Stéphane

Where do I place this code ? 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors