Forum Discussion
Convert few columns into rows in an existing table
- 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
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
Hi v-yulgu-msft,
Thanks for your support. If I unpivot 4 columns other columns will remain same but the rows will be splitted based on the mentioned 4 columns value that's what I don't want to be. I want other columns value as a consolidated one the reason why I wan to unpivot these 4 columns in a separate table. Each record is not repeating three times, three 1s are different three values, I kept it same to mean it as a group.
Thanks for the DAX expression, I will try it and get back to you if it doesn't serve my purpose.