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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Merging columns but ignore repeating items across a row

Hi,

this is my initial table:

 

Symbols
(*)
(^)
(!)
(~)

 

I want to create a list of all the combinations of these 4 symbols.

The order of the symbols doesn't matter, its just the combination that matters.

eg, (*)(!) = (!)(*)

also, I want to exclude repeating, eg:

(*)(*)(*)(!) should just be (*)(!)

 

So here's my code:

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Tbl_symbol"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Symbols", type text}, {"Definition", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom",{"Custom"},#"Added Custom",{"Custom"},"Added Custom",JoinKind.LeftOuter),
    #"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Symbols"}, {"Symbols.1"}),
    #"Merged Queries1" = Table.NestedJoin(#"Expanded Added Custom",{"Custom"},#"Expanded Added Custom",{"Custom"},"Expanded Added Custom",JoinKind.LeftOuter),
    #"Expanded Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries1", "Expanded Added Custom", {"Symbols", "Symbols.1"}, {"Symbols.2", "Symbols.1.1"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Expanded Added Custom",{"Definition", "Index", "Custom"})
in
    #"Removed Columns"

 

 

 

And this is what I get:

yeders_0-1661866559187.png

I'd like to merge the columns now, but I'm not sure how to ONLY include the column if it is distinct from the existing items. Also, this may not manage the whole (*)(!) being the same as (!)(*). One step at a time, perhaps! My initial merge queries could be optimised for a better outcome?

Thanks so much in advance for your help.

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

It sounds like you want the set of all possible subsets of these four symbols.

 

If that's correct, you may be interested in my comment on @smpa01's combinatorics blog post. In particular, you can generate the list of combinations as follows:

let
  Source = {"(*)", "(^)", "(!)", "(~)"},
  N = List.Count(Source),
  Subsets =
      List.Transform(
          {0..Number.Power(2, N)-1},
          (i) => List.Transform(
                     {0..N-1},
                     (j) => if Number.Mod(Number.IntegerDivide(i, Number.Power(2, j)), 2) = 1
                            then Source{j}
                            else null
                 )
      ),
  Concatenate = List.Transform(Subsets, each Text.Combine(List.RemoveNulls(_), ""))
in
  Concatenate

 

Output:

AlexisOlson_0-1661884222261.png

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1661912310078.png

 

AlexisOlson
Super User
Super User

It sounds like you want the set of all possible subsets of these four symbols.

 

If that's correct, you may be interested in my comment on @smpa01's combinatorics blog post. In particular, you can generate the list of combinations as follows:

let
  Source = {"(*)", "(^)", "(!)", "(~)"},
  N = List.Count(Source),
  Subsets =
      List.Transform(
          {0..Number.Power(2, N)-1},
          (i) => List.Transform(
                     {0..N-1},
                     (j) => if Number.Mod(Number.IntegerDivide(i, Number.Power(2, j)), 2) = 1
                            then Source{j}
                            else null
                 )
      ),
  Concatenate = List.Transform(Subsets, each Text.Combine(List.RemoveNulls(_), ""))
in
  Concatenate

 

Output:

AlexisOlson_0-1661884222261.png

Anonymous
Not applicable

Excellent! Thank you so very much.

ND_Pard
Helper II
Helper II

Hmmmm ... perhaps if you showed/provided us the Source and the desired outcome, we may be able to assist you quicker?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors