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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Solution Authors
Top Kudoed Authors