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
anandav
Skilled Sharer
Skilled Sharer

Generating row value combinations

Hi,

 

I am trying to generate combination of values found in row data.

 

Source Data

CustomerColumn2
PaulA
PaulB
PaulC
TomD
TomE
TomF
JerryH
JerryI
JerryJ

 

Expected Output

CustomerCombined Column
PaulA-B
PaulA-C
PaulB-C
TomD-E
TomD-F
TomE-F
JerryH-I
JerryH-J
JerryI-J

 

Any suggestion on how this can be achieved either in M or DAX?

Even if the combinations are repeated, for example  A-B and B-A, I am fine with that.

 

Thanks in advance for your help.

Anand.

3 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

This seems close, albeit with duplicates:

 

Table = 
VAR __tmpTable1 = SELECTCOLUMNS(ALL('Data'),"__Customer",[Customer],"__Column2",[Column2])
VAR __tmpTable2 = SELECTCOLUMNS(ALL('Data'),"___Customer",[Customer],"___Column2",[Column2])
VAR __tmpTable3 = FILTER(GENERATE(__tmpTable1,__tmpTable2),[__Customer]=[___Customer]&&([__Column2]>[___Column2]||[__Column2]<[___Column2]))
VAR __tmpTable4 = ADDCOLUMNS(__tmpTable3,"__CombinedColumn",[__Column2]&"-"&[___Column2])
RETURN SELECTCOLUMNS(__tmpTable4,"Customer",[__Customer],"Combined Column",[__CombinedColumn])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi,

 

See the image.  Download file from here.

 

Untitled.png


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

View solution in original post

@Greg_Deckler,

Thanks to your solution I made a minor adjustment to step3. Removed "[__Column2]>[___Column2]||". And that gave the exact result I nmeeded.

 

VAR __tmpTable3 =
    FILTER (
        GENERATE ( __tmpTable1, __tmpTable2 ),
        [__Customer] = [___Customer]
            && ([__Column2] < [___Column2] )
    )

 

Capture.JPG

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

 

Here's the M code i used

 

let
    Source = Table.NestedJoin(Data,{"Customer"},#"Data (2)",{"Customer"},"Data (2)",JoinKind.LeftOuter),
    #"Expanded Data (2)" = Table.ExpandTableColumn(Source, "Data (2)", {"Column2"}, {"Column2.1"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Data (2)", "Custom", each [Column2]&"-"&[Column2.1]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column2", "Column2.1"})
in
    #"Removed Columns"


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

@Ashish_Mathur,

I downloaded the data into a table named Data.

Then from Get Source I selected Blank Query and type your M code.

But it does not create a table. I get the following:

Capture.JPG

Hi,

 

See the image.  Download file from here.

 

Untitled.png


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

@Ashish_Mathur,

That is a very simple solution using M.

Thanks a lot.

 

It needs some tweaking to remove same letter combination, e.g. A-A, but still very easy to achieve.

Thank you for your help.

You are welcome.


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

This seems close, albeit with duplicates:

 

Table = 
VAR __tmpTable1 = SELECTCOLUMNS(ALL('Data'),"__Customer",[Customer],"__Column2",[Column2])
VAR __tmpTable2 = SELECTCOLUMNS(ALL('Data'),"___Customer",[Customer],"___Column2",[Column2])
VAR __tmpTable3 = FILTER(GENERATE(__tmpTable1,__tmpTable2),[__Customer]=[___Customer]&&([__Column2]>[___Column2]||[__Column2]<[___Column2]))
VAR __tmpTable4 = ADDCOLUMNS(__tmpTable3,"__CombinedColumn",[__Column2]&"-"&[___Column2])
RETURN SELECTCOLUMNS(__tmpTable4,"Customer",[__Customer],"Combined Column",[__CombinedColumn])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler,

Thanks to your solution I made a minor adjustment to step3. Removed "[__Column2]>[___Column2]||". And that gave the exact result I nmeeded.

 

VAR __tmpTable3 =
    FILTER (
        GENERATE ( __tmpTable1, __tmpTable2 ),
        [__Customer] = [___Customer]
            && ([__Column2] < [___Column2] )
    )

 

Capture.JPG

@Greg_Deckler,

That's works! Excellent solution!

Thanks a lot for the prompt reply.

 

I can sort out the duplicate combination.

Thanks you.

Aree
Resolver I
Resolver I

Not sure if this helps you or if i understand what you are attempting to achieve becuase the Combine Column values seem random.
If am wrong and they are not random i apologise.

 

For a given Customer Paul join the first letter of their name with the value in Column2

Combination = [Column2] &"-"& LEFT( [Customer],1 )

The result will be: A-P

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.