Search code examples
powerbipowerquery

Power Query Operation to append 3 categorical columns and their respective measures


I am trying to append 3 date columns from different months into single column (this stage has been reached post multiple operations) into a single one in Power Query editior. Not sure how to do this

From this :

Actual Data

To this :

Desired State

I tried Unpivoting, Transpose etc but not getting the desired results


Solution

  • Let's assume your column names are:

    Date | Count | Date1 | Count1 | Date2 | Count2
    

    Since you are not allowed to have duplicate column names.

    You can achieve what you need, by appending columns...

    ...
    ...
      PreAppend = #"Your Previous Step",
      Appended = Table.FromColumns({
        PreAppend[Date] & PreAppend[Date1] & PreAppend[Date2],
        PreAppend[Count] & PreAppend[Count1] & PreAppend[Count2]
        }, { "Date", "Count" })
    in
      Appended
    

    This alternative will append the even and odd columns togther:

    ...
    ...
      tblColumns = Table.ToColumns(#"Your Previous Step"),
      Appended = Table.FromColumns({
        List.Combine(List.Alternate(tblColumns, 1, 1, 1)),
        List.Combine(List.Alternate(tblColumns, 1, 1))
        }, {"Date", "Count"})
    in
      Appended