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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
newpbiuser01
Helper IV
Helper IV

Unpivoting in DAX

Hello,

 

I currently have 8 different tables that are related to one another and I'm pulling in a name from each of the tables to create a comma seperated list of reportees for each manager. Unfortunately, I can't do it in Power Query unless I merge the 8 tables one by one and given the size of the data and the number of tables (8) that's really messing up the performance! 

 

So instead I add the relationships between the tables and then generate the table 1 reportees column. What I'd like to do now is unpivot the Table 1 below to get each of the reportees for each manager (Table 2).

 

Table I

ManagerReportees
BobMike, Andy, Liz, Christine
SallyLiz, Christine
TomDave, Sally, Liz, Christine

 

I need to get this:

ManagerReportee
BobMike
BobAndy
BobLiz
BobChristine
SallyLiz
SallyChristine
TomDave
TomSally
TomLiz
TomChristine

 

Has anyone tried to do this and know how I could do it in DAX? 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @newpbiuser01 

Please try

Table2 =
seleactcolumns (
    GENERATE (
        Table1,
        VAR String = Table1[Reportees]
        VAR Items =
            SUBSTITUTE ( String, ", ", "|" )
        VAR Length =
            PATHLENGTH ( Items )
        VAR T =
            GENERATESERIES ( 1, Length, 1 )
        RETURN
            SELECTCOLUMNS ( T, "Reportee", PATHITEM ( Items, [Value] ) )
    ),
    "Manager",
    [Manager],
    "Reportee",
    [Reportee]
)

 

 

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @newpbiuser01 

Please try

Table2 =
seleactcolumns (
    GENERATE (
        Table1,
        VAR String = Table1[Reportees]
        VAR Items =
            SUBSTITUTE ( String, ", ", "|" )
        VAR Length =
            PATHLENGTH ( Items )
        VAR T =
            GENERATESERIES ( 1, Length, 1 )
        RETURN
            SELECTCOLUMNS ( T, "Reportee", PATHITEM ( Items, [Value] ) )
    ),
    "Manager",
    [Manager],
    "Reportee",
    [Reportee]
)

 

 

Thank you!

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Kudoed Authors