Search code examples
pythonexcelpowerquerypowerbi-desktopm

Is there any way to rearrange excel data without copy paste?


I have an excel file that contain country name and dates as column name.

+---------+------------+------------+------------+
| country | 20/01/2020 | 21/01/2020 | 22/01/2020 |
+--------- ------------+------------+------------+
| us      |   0        |   5        |       6    |
+---------+------------+------------+------------+
| Italy   | 20         |   23       |      33    |
+--------- ------------+------------+------------+
| India   |   0        |   0        |       6    |
+---------+------------+------------+------------+

But i need to arrange column names country, date, and count. Is there any way to rearrange excel data without copy paste.

final excel sheet need to look like this

+---------+------------+------------+
| country | date       | count      | 
+--------- ------------+------------+
| us      | 20/01/2020 |   0        | 
+---------+------------+------------+
| us      | 21/01/2020 |   5        |   
+---------+------------+------------+
| us      | 22/01/2020 |   6        |    
+---------+------------+------------+
| Italy   | 20/01/2020 |   20       |     
+--------- ------------+------------+
| Italy   | 21/01/2020 |   23       |     
+--------- ------------+------------+
| Italy   | 22/01/2020 |   33       |      
+--------- ------------+------------+
| India   | 20/01/2020 |   0        | 
+---------+------------+------------+


Solution

  • Power Pivot is the best way, but if you want to use formulas: In F1 enter:

    =INDEX($A$2:$A$4,ROUNDUP(ROWS($1:1)/3,0))
    

    and copy downward. In G1 enter:

    =INDEX($B$1:$D$1,MOD(ROWS($1:1)-1,3)+1)
    

    and copy downward. H1 enter:

    =INDEX($B$2:$D$4,ROUNDUP(ROWS($1:1)/3,0),MOD(ROWS($1:1)-1,3)+1)
    

    and copy downward

    enter image description here

    The 3 in these formulas is because we have 3 dates in the original table.