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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KatkaS
Post Patron
Post Patron

Grouping by?

Hello

could anyone please help me with following?

I have below table and I would need to make pairs of Codes by column Name - is there a way how to do it in Power BI??

 

example - I would need a result of a new table where first column would be Name and in the second column combination of 2 Codes: 

 

Thank you very much!

 

 

ORIGINAL TABLE:

CodeName
Code1Name1

Code2

Name1
Code3Name1

Code1

Name2

Code2

Name2
Code2Name3
Code3Name3
Code5Name3
Code6Name3

 

 

NEW TABLE:

CodeName
Code1 + Code2Name1

Code1 + Code3

Name1
Code2 + Code3Name1

Code1 + Code2

Name2

Code2 + Code3

Name3
Code2 + Code5Name3
Code3 + Code6Name3
Code5 + Code6Name3

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@KatkaS Try:

Table 2 = 
    VAR __Table = 
        GENERATE(
            'TableCodes',
            DISTINCT(SELECTCOLUMNS(FILTER(ALL(TableCodes),[Name] = EARLIER(TableCodes[Name])),"__Code",[Code]))
        )
RETURN
    SELECTCOLUMNS(
        ADDCOLUMNS(
            FILTER(__Table,[Code] <> [__Code]),
            "__New",[Code] & " + " & [__Code]
        ),
        "Name",[Name],
        "Code",[__New]
    )


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
KatkaS
Post Patron
Post Patron

@Greg_Deckler you are a genius, thank you!

Greg_Deckler
Super User
Super User

@KatkaS Try:

Table 2 = 
    VAR __Table = 
        GENERATE(
            'TableCodes',
            DISTINCT(SELECTCOLUMNS(FILTER(ALL(TableCodes),[Name] = EARLIER(TableCodes[Name])),"__Code",[Code]))
        )
RETURN
    SELECTCOLUMNS(
        ADDCOLUMNS(
            FILTER(__Table,[Code] <> [__Code]),
            "__New",[Code] & " + " & [__Code]
        ),
        "Name",[Name],
        "Code",[__New]
    )


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler , may I have an additional question...?

Your solution works as charm, but I received new file with added information - entity code (new column in the original table)

 

It means that one person could work for multiple companies and have various code combinations.

I would need to find out combinations (as you already showed me how), but within one company.

 

Could you look at that? Thank you very much!

@KatkaS I imagine something along the lines of:

Table 2 = 
    VAR __Company = "Company 1"
    VAR __Table = 
        GENERATE(
            FILTER('TableCodes', [Company] = __Company
            DISTINCT(SELECTCOLUMNS(FILTER(ALL(TableCodes),[Name] = EARLIER(TableCodes[Name] && [Company] = __Company)),"__Code",[Code]))
        )
RETURN
    SELECTCOLUMNS(
        ADDCOLUMNS(
            FILTER(__Table,[Code] <> [__Code]),
            "__New",[Code] & " + " & [__Code]
        ),
        "Name",[Name],
        "Code",[__New]
    )


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I appreaciate you support very much! I tried above solution, but it returnes an syntax error.. could you please loot at it? I will try to send you the dashboard via personal message. Thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.