Forum Discussion

pointtoshare's avatar
pointtoshare
Frequent Visitor
9 years ago
Solved

Convert few columns into rows in an existing table

Hi,

I have one table contains columns: A, B, C, D, E, F, G, H, I, J, K, L. I want to convert only E, F, G, H columns into rows . How can I go for it.

 

Thanks in advance.

  • v-yulgu-msft's avatar
    v-yulgu-msft
    9 years ago

    Hi pointtoshare,

     

    If we Unpivot these 4 columns: E,F,G,H, we will get below result.  The other columns are still kept as original.  From the image which is your expected output, I am confused why each record repeats for three times.

     

    To your second question"can I convert columns into rows in a calculated table", it is not available to pivot/unpivot a calculated table in query editor mode. However, to work around this issue, please try below DAX:

    New Table =
    UNION (
        SELECTCOLUMNS (
            'Convert column',
            "A", 'Convert column'[A],
            "Col1", "E",
            "Col2", 'Convert column'[E]
        ),
        SELECTCOLUMNS (
            'Convert column',
            "A", 'Convert column'[A],
            "Col1", "F",
            "Col2", 'Convert column'[F]
        ),
        SELECTCOLUMNS (
            'Convert column',
            "A", 'Convert column'[A],
            "Col1", "G",
            "Col2", 'Convert column'[G]
        ),
        SELECTCOLUMNS (
            'Convert column',
            "A", 'Convert column'[A],
            "Col1", "H",
            "Col2", 'Convert column'[H]
        )
    )

     

    Best regards,
    Yuliana Gu

7 Replies

  • Sean's avatar
    Sean
    Icon for Community Champion rankCommunity Champion

    In the Query Editor

    1) Select the 4 columns E, F, G, H

    2) Transform tab - Unpivot Columns

    3) Rename new columns as necessary

    • pointtoshare's avatar
      pointtoshare
      Frequent Visitor

      Hi Sean,

      Thanks for your prompt reply.

      The method you proposed is working but it breaks other columns setup as well. I want to keep other columns as it is. Is there any way to move the column E, F, G, H to another new table as table rows? Or, can I convert columns into rows in a calculated table?

       

      Thanks.

      • Sean's avatar
        Sean
        Icon for Community Champion rankCommunity Champion

        Post sample data in its original format and then desired output from that data.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Your solution works perfectly, but how do I apply a filter using this solution