Forum Discussion

175429's avatar
175429
Copper Contributor
Oct 28, 2024

Pivot/Transpose Issue

Hello all,

 

On the left is my current table. I want it to look like the table on the right. (I manually created a sample for reference, but my table has over 7000 rows so I can't manually create the whole thing).

 

As you can see I have multiple entries per day. When I transpose it in PQ, it shortens it to one entry per day, basically erasing all the other entries.

 

Help would be greatly appreciated.

 

Thank you!

      • 175429 

        As an alternative: a VBA macro.

         

        Sub FillOverview()
            Dim s As Long
            Dim m As Long
            Dim t As Long
            Application.ScreenUpdating = False
            Range("H2:N10000").ClearContents
            m = Range("A" & Rows.Count).End(xlUp).Row
            t = 1
            For s = 2 To m
                Select Case Left(Range("A" & s).Value, 2)
                    Case "01"
                        t = t + 1
                        Range("H" & t).Resize(1, 3).Value = Range("C" & s).Resize(1, 3).Value
                        Range("N" & t).Value = Range("F" & s).Value
                        Range("K" & t).Value = Range("B" & s).Value & ""
                    Case "02"
                        Range("L" & t).Value = Range("B" & s).Value & ""
                    Case "03"
                        Range("M" & t).Value = Range("B" & s).Value & ""
                End Select
            Next s
            Application.ScreenUpdating = True
        End Sub

        See the Visual Basic Editor.

         

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    175429 

    Just updated my previous post (download the Updated version please)

    A Sort step wasn't at the right place in terms of efficiency

    • 175429's avatar
      175429
      Copper Contributor
      What is the new file supposed to show me?
      • Lorenzo's avatar
        Lorenzo
        Silver Contributor
        Exactly the same thing. As I mentioned earlier the query is more efficient in the Update version

Resources