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
Anonymous
Not applicable

Inverse of unpivot

I have the following data set of accounts and team members, no account will have more than 2/3 team members however I want it with the account id column to be unique. Preferably I would like this to be done in Power Query but if it can only be done in dax then that could work.

 

Account ID | Team Member

1                 | Alice

1                 | Bob

1                 | Chris

2                 | Dan

3                 | Emma

3                 | Frank

 

What I want to do is end up with 

 

Account ID | First User | Second User | Third User

1                 | Alice        | Bob               | Chris 

2                 | Dan         | null                | null

3                 | Emma     | Frank             | null

 

I would know how to go from what I want to what I have with unpivot however I have been unable to do the reverse with group or pivot.

 

Thank you for your help

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Here is one way using DAX calculated Table

 

From the Modelling Tab>>New Table

 

Table =
SUMMARIZE (
    Table1,
    Table1[Account ID ],
    "First User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 1
        )
    ),
    "Second User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 2
        )
    ),
    "Third User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 3
        )
    )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Here is one way using DAX calculated Table

 

From the Modelling Tab>>New Table

 

Table =
SUMMARIZE (
    Table1,
    Table1[Account ID ],
    "First User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 1
        )
    ),
    "Second User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 2
        )
    ),
    "Third User", CALCULATE (
        FIRSTNONBLANK ( Table1[ Team Member], 1 ),
        FILTER (
            VALUES ( Table1[ Team Member] ),
            RANKX (
                VALUES ( Table1[ Team Member] ),
                CALCULATE ( VALUES ( Table1[ Team Member] ) )
            )
                = 3
        )
    )
)

Regards
Zubair

Please try my custom visuals

@Anonymous

 

inverse unpivot.png


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Thanks @Zubair_Muhammad that seems to be perfect.

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.