Forum Discussion
Unpivot Question
- Anonymous1 year ago
Hi SnowBoardTim ,
Thank you for the patience! If the issue is still not resolve,please refer the answer below:
There is a limitation when importing merged columns to Power BI , the first column will reflect as is, while the other column will appear blank in the header. To avoid this issue, unmerge the columns in the header and copy the same header to all the columns manually. Then, the rows can be merged using the m code below. Please change the source as per your requirements. Attached the pbix file for reference.let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText("i45WCs4sSVXSUXJMTs4vzSsBsgJSizLzUwzhLCM4yxjOMoGzTOEsMzjLXClWJ1rJxxEoEAHEfvqORJEgTb6pJUX5Bfk5mcWkao4FAA==", BinaryEncoding.Base64),
Compression.Deflate
)
),
let _t = ((type nullable text) meta [Serialized.Text = true]) in
type table [#"(blank)" = _t, #"(blank).1" = _t, #"2024 Actual W Forecast" = _t, #"2024 Actual W Forecast.1" = _t, #"2024 Actual W Forecast.2" = _t, #"2024 Actual W Forecast.3" = _t, #"2024 Actual W Forecast.4" = _t, #"2024 Actual W Forecast.5" = _t, #"2024 Actual W Forecast.6" = _t]
),
OriginalHeaders = Table.ColumnNames(Source),
// Cleaned headers: remove .1/.2 suffixes and replace (blank) with space
CleanedHeaders = List.Transform(
OriginalHeaders,
each Text.Replace(Text.BeforeDelimiter(_, "."), "(blank)", "")
),
FirstRow = Source{0},
FirstRowValues = Record.ToList(FirstRow),
// Combine cleaned header + first row value
CombinedHeaders = List.Transform(
List.Zip({CleanedHeaders, FirstRowValues}),
each Text.Combine(List.RemoveNulls(_), " ")
),
DataWithoutFirstRow = Table.Skip(Source, 1),
FinalTable = Table.RenameColumns(DataWithoutFirstRow, List.Zip({Table.ColumnNames(DataWithoutFirstRow), CombinedHeaders}))
in
FinalTableIf this answer meets your requiremnets, consider accepting it as solution.
Thank you.
Hi SnowBoardTim ,
I just wanted to kindly follow up to see if you had a chance to review my previous response. Please let me know if it was helpful, and feel free to reach out if needed any further assistance. If our community member's repsonse addressed your query, please Accept the answer so that it will be helpful to others to find it more quickly.
Thank you for being a part of Microsoft Fabric Community Forum!
- SnowBoardTim1 year agoNew Member
I was not able to finalize the solution. I replied to your previous comments. Thanks for the help!