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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
binayjethwa
Helper IV
Helper IV

How to unpivot columns using power bi dax and not power query

Hi ,

 

For sample , i have the following data , Basically i have multiple columns where i need to take only selected columns and create a table out of it , I used summarize and extracted the columns I needed , But since its a table created using dax i cannot edit it in power query , so i need to use dax to unpivot columns and get my data as below. Please help 

 

EMP IDName Country Sales
123BinayIndia 10
123Binay1Malaysia10
124Binay3Singapore11
125Binay4Thailand12
126Binay5Philliphines13

 

I want to have a table like below . 

 

EMP IDName India MalaysiaSingaporeThailandPhilliphines
123Binay10    
123Binay1 10   
124Binay3  11  
125Binay4   12 
126Binay5    13
       
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @binayjethwa ,

 

Please try this formula of the calculated table.

 

Pivot Table =
VAR _tempTable =
    ADDCOLUMNS (
        'Table',
        "@India",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "India"
                )
            ),
        "@Malaysia",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Malaysia"
                )
            ),
        "@Singapore",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Singapore"
                )
            ),
        "@Thailand",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Thailand"
                )
            ),
        "@Philliphines",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Philliphines"
                )
            )
    )
VAR _selectColumns =
    SELECTCOLUMNS (
        _tempTable,
        "Emp ID", [EMP ID],
        "Name", [Name],
        "India", [@India],
        "Malaysia", [@Malaysia],
        "Singapore", [@Singapore],
        "Thailand", [@Thailand],
        "Philliphines", [@Philliphines]
    )
RETURN
    DISTINCT ( _selectColumns )

 

As you can see, I added a few rows to your sample data to show the sum up in the output.

Before:

vstephenmsft_0-1690188983853.png

After:

vstephenmsft_1-1690189008721.png

By the way, this conversion should be pivot, and unpivot is the case of the other way around.

Pivot and Unpivot with Power BI - RADACAD

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

View solution in original post

6 REPLIES 6
PaulDBrown
Community Champion
Community Champion

You can use the matrix visual as follows:

Matrix.png

If you need the countries sorted, you can add a sorting colum (preferably using a dimension table). Yoou can also turn off the subtotals/totals





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






@PaulDBrown  I will not be able to use matrix as i need to show around 25 fields in row section and i will have scroll issue, hence i need to use table visual only . 

Arul
Super User
Super User

@binayjethwa ,

Try the below DAX code in calculated table, 

Unpivot Table = 
VAR _tempTable =
    ADDCOLUMNS (
        'Table (7)',
        "@India", CALCULATE ( MAX ( 'Table (7)'[Sales] ), 'Table (7)'[Country ] = "India" ),
        "@Malaysia", CALCULATE ( MAX ( 'Table (7)'[Sales] ), 'Table (7)'[Country ] = "Malaysia" ),
        "@Singapore", CALCULATE ( MAX ( 'Table (7)'[Sales] ), 'Table (7)'[Country ] = "Singapore" ),
        "@Thailand", CALCULATE ( MAX ( 'Table (7)'[Sales] ), 'Table (7)'[Country ] = "Thailand" ),
        "@Philliphines", CALCULATE ( MAX ( 'Table (7)'[Sales] ), 'Table (7)'[Country ] = "Philliphines" )
    )
VAR _selectColumns =
    SELECTCOLUMNS (
        _tempTable,
        "Emp ID", [EMP ID],
        "Name", [Name ],
        "India", [@India],
        "Malaysia", [@Malaysia],
        "Singapore", [@Singapore],
        "Thailand", [@Thailand],
        "Philliphines", [@Philliphines]
    )
RETURN
    _selectColumns




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Hi @Arul ,

 

I tried the same way , basically i have a large table , from which i need those columns and country wise sales . the output i receive is having multiple rows for each country , is there any way  we can add all the values for that country and show as  sum up value. 

 

I want result in this way if there are multipe rows for particular column , it should sum up and display per emp , one row with sales value.  Let me know if we can workaround this.

 

EMP IDName India MalaysiaSingaporeThailandPhilliphines
123Binay10    
128Binay1 10   
124Binay3  11  
125Binay4   12 
126Binay5    13

 

Anonymous
Not applicable

Hi @binayjethwa ,

 

Please try this formula of the calculated table.

 

Pivot Table =
VAR _tempTable =
    ADDCOLUMNS (
        'Table',
        "@India",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "India"
                )
            ),
        "@Malaysia",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Malaysia"
                )
            ),
        "@Singapore",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Singapore"
                )
            ),
        "@Thailand",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Thailand"
                )
            ),
        "@Philliphines",
            CALCULATE (
                SUM ( 'Table'[Sales] ),
                FILTER (
                    'Table',
                    [EMP ID] = EARLIER ( 'Table'[EMP ID] )
                        && [Name] = EARLIER ( 'Table'[Name] )
                        && [Country] = "Philliphines"
                )
            )
    )
VAR _selectColumns =
    SELECTCOLUMNS (
        _tempTable,
        "Emp ID", [EMP ID],
        "Name", [Name],
        "India", [@India],
        "Malaysia", [@Malaysia],
        "Singapore", [@Singapore],
        "Thailand", [@Thailand],
        "Philliphines", [@Philliphines]
    )
RETURN
    DISTINCT ( _selectColumns )

 

As you can see, I added a few rows to your sample data to show the sum up in the output.

Before:

vstephenmsft_0-1690188983853.png

After:

vstephenmsft_1-1690189008721.png

By the way, this conversion should be pivot, and unpivot is the case of the other way around.

Pivot and Unpivot with Power BI - RADACAD

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

Anonymous
Not applicable

Hi @Anonymous 

I am trying to create similar values in which i have few columns and i want to see if value in Key Figure column is equal to "Requested Sale Order" then it should only give me the values of two other coulmns called "Requested Shipped Order and "Requested Shipped Order Value" Similarly if key figure is equal to "Shipped Sales Order " then it should populate values of "Shipped Sales " and "Shipped Sales Order value " .

I try this in Matrix table but as soon as i enterd the values its showing me other columns as well ,please see below for better explanation :

Data_!2.JPG
My Desire Result is :

Data_123.JPG

Request you to please help me if its possible:

 

Thanks,

Ashish




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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