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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
GhostTIT
New Member

need solution to Rearrange with Excel data //attach file

SETparticipant1typeratio%participant2type2ratio%2participant3type3ratio%3
1Mr.AAAHead50Mr.Johnpartner25Mr.Oneassistant25
2Mr.BBBHead100      
3Mrs.CCCHead80Mrs.Sarahassistant0Mrs.threepartner10

 

[top] I want to rearrange with 50 SET, each Set has 10 participants (3 columns in 1 participant)

I want to transform to data [below]

 

SETParticipantTypeRatio%
1Mr.AAAHead50
1Mr.Johnpartner25
1Mr.Oneassistant25
2Mr.BBBHead100
3Mrs.CCCHead80
3Mrs.Sarahassistant0
3Mrs.threepartner10

 

how to do it , i try unpivot column many times and get stunning T_T

thank you so much. 🙂

 

 

file attach : download excel file 

 

 

 

 

 

 

6 REPLIES 6
Anonymous
Not applicable

Hi @GhostTIT ,

 

The first method is to copy out two tables, three tables with different participant, type, and ratio. Then append to ensure that the column names are consistent.

Append queries - Power Query | Microsoft Learn

The second method is as follows.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIt0nN0dAQyPFITU4CUqQFE0Cs/Iw/IKkgsKslLLQKyjEwhEv55qUBGYnFxZnFJYl4JRCZWJ1rJCCLv5OSEMM3QAGQcOgKpNoaoTk5ORqi2gNhdrBecWJSYgWYLTK4koyg1FcVlhgZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SET = _t, participant1 = _t, #"type" = _t, #"ratio%" = _t, participant2 = _t, type2 = _t, #"ratio%2" = _t, participant3 = _t, type3 = _t, #"ratio%3" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SET", Int64.Type}, {"participant1", type text}, {"type", type text}, {"ratio%", Int64.Type}, {"participant2", type text}, {"type2", type text}, {"ratio%2", Int64.Type}, {"participant3", type text}, {"type3", type text}, {"ratio%3", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"SET"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("1", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Attribute.1", Splitter.SplitTextByDelimiter("2", QuoteStyle.Csv), {"Attribute.1.1", "Attribute.1.2"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Attribute.1.1", type text}, {"Attribute.1.2", type text}}),
    #"Split Column by Delimiter2" = Table.SplitColumn(#"Changed Type2", "Attribute.1.1", Splitter.SplitTextByDelimiter("3", QuoteStyle.Csv), {"Attribute.1.1.1", "Attribute.1.1.2"}),
    #"Changed Type3" = Table.TransformColumnTypes(#"Split Column by Delimiter2",{{"Attribute.1.1.1", type text}, {"Attribute.1.1.2", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type3",{"Attribute.1.1.2", "Attribute.1.2", "Attribute.2"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Attribute.1.1.1", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Attribute.1.1.1"}, {{"Count", each _, type table [#"SET - Copy"=nullable number, Attribute.1.1.1=nullable text, Value=any]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Value", "Index"}, {"Custom.Value", "Custom.Index"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Count"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Attribute.1.1.1]), "Attribute.1.1.1", "Custom.Value"),
    #"Filtered Rows" = Table.SelectRows(#"Pivoted Column", each ([#"ratio%"] <> null))
in
    #"Filtered Rows"

vstephenmsft_0-1688007500072.png

You download my attachment for more details.

 

Best Regards,

Stephen Tao

 

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

i've test your code and it really broke T_T 

because If you put no. 1-2-3 behind attribure out (participate,type,ratio) 

the resulf will not connect to the correct position. 

 

look   the result data have to be

Mr.AAA = Head = 50

 

but in your result 

Mr. AAA = Head = 10  and other rows also switch so on.. 

 

 

 

AlienSx
Super User
Super User

Hi, @GhostTIT 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    to_rows = List.Buffer(List.Transform(Table.ToRows(Source), (x) => List.RemoveNulls(x))),
    f = (lst as list) =>
        [a = List.First(lst),
        b = List.Split(List.Skip(lst), 3),
        c = List.Transform(b, (x) => {a} & x)][c],
    out = Table.FromRows(List.Combine(List.Transform(to_rows, f)), {"SET", "Participant", "Type", "Ratio%"})
in
    out
slorin
Super User
Super User

Hi

 

let
Source = YourSource,
Data = Table.AddColumn(Source, "Data", each Table.FromRows(List.Split(List.Skip(Record.ToList(_)),3),{"Participant", "Type", "Ratio%"})),
SelectColumns = Table.SelectColumns(Data,{"SET", "Data"}),
Expand = Table.ExpandTableColumn(SelectColumns, "Data", {"Participant", "Type", "Ratio%"}, {"Participant", "Type", "Ratio%"})
in
Expand

Stéphane 

It's not working ... code is....

--------------------------------------

//OLD FirstRUN
/*
let
Source = Excel.Workbook(File.Contents("C:\Users\Ghost-ROG\Desktop\rearrange_data.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"SET", Int64.Type}, {"participant1", type text}, {"type", type text}, {"ratio%", Int64.Type}, {"participant2", type text}, {"type2", type text}, {"ratio%2", Int64.Type}, {"participant3", type text}, {"type3", type text}, {"ratio%32", Int64.Type}})
in
#"Changed Type"

*/

//NEW *not working
let
Source = Excel.Workbook(File.Contents("C:\Users\Ghost-ROG\Desktop\rearrange_data.xlsx"), null, true),
Data = Table.AddColumn(Source, "Data", each Table.FromRows(List.Split(List.Skip(Record.ToList(_)),3),{"Participant", "Type", "Ratio%"})),
SelectColumns = Table.SelectColumns(Data,{"SET", "Data"}),
Expand = Table.ExpandTableColumn(SelectColumns, "Data", {"Participant", "Type", "Ratio%"}, {"Participant", "Type", "Ratio%"})
in
Expand

 

-------------------------

At first it show ": The field 'Data' already exists in the record."

then I change Data to Data1 in line2

it show The column 'SET' of the table wasn't found.

 

What i should do next?

and I don't understand that code. Is it have to write down the whole code?

 

 

 

 

Hi 

There's a step between Source and Data

 

Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],

 

Stéphane 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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