Transposing a table

%3CLINGO-SUB%20id%3D%22lingo-sub-2133014%22%20slang%3D%22en-US%22%3ETransposing%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2133014%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20panel%20data%20table.%20The%20value%20of%20an%20item%20is%20recorded%20each%20year.%20The%20column%20has%20values%20corresponding%20to%20the%20year%20(%20table%201).%20So%2C%20there%20are%2011%20years%20and%2011%20different%20columns.%20I%20want%20to%20have%20only%202%20columns%2C%20all%20years%20in%201%20column%20(table%202).%20Simple%20transpose%20doesn't%20work.%20I%20also%20tried%20sumifs%20but%20didn't%20succeed.%20Please%20advise.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2133014%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2133051%22%20slang%3D%22en-US%22%3ERe%3A%20Transposing%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2133051%22%20slang%3D%22en-US%22%3EHi%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20Power%20Query%20Unpivot%20Other%20Columns%20function%20is%20perfect%20for%20this%3CBR%20%2F%3E%3CBR%20%2F%3EApologies%20for%20the%20music%20choice%20%3CA%20href%3D%22https%3A%2F%2Fyoutu.be%2F2c06jmrAb3I%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fyoutu.be%2F2c06jmrAb3I%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWyn%3CBR%20%2F%3EMVP%3CBR%20%2F%3EUTC%20%2B%208%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2133340%22%20slang%3D%22de-DE%22%3ESubject%3A%20Transposing%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2133340%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F966104%22%20target%3D%22_blank%22%3E%40Pussyk%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20Mr.%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3EWyn%20Hopkins%20%3C%2FA%3E%20said%2C%20Power%20Query%20is%20the%20most%20suitable%20tool%20for%20this.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EHere%20is%20some%20information%20and%20help%20for%20the%20first%20steps%20from%20Microsoft.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ECombine%20data%20from%20multiple%20data%20sources%20(Power%20Query)%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fcombine-data-from-multiple-data-sources-power-query-70cfe661-5a2a-4d9d-a4fe-586cc7878c7d%3Fui%3Den-US%26amp%3Brs%3Den-US%26amp%3Bad%3DUS%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fcombine-data-from-multiple-data-sources-power-query-70cfe661-5a2a-4d9d-a4fe-586cc7878c7d%3Fui%3Den-US%26amp%3Brs%3Den-US%26amp%3Bad%3DUS%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Knowing%20the%20Excel%20version%20and%20operating%20system%20would%20be%20an%20advantage.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2133515%22%20slang%3D%22en-US%22%3ERe%3A%20Transposing%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2133515%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F966104%22%20target%3D%22_blank%22%3E%40Pussyk%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnpivoting%20tables%20is%20core%20functionality%20of%20Power%20Query.%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20is%20also%20possible%20to%20effect%20such%20a%20transformation%20using%20formulas%20but%20that%20involves%20detailed%20messing%20about%20with%20row%20and%20column%20indices.%26nbsp%3B%20It%20is%20most%20elegantly%20performed%20in%20the%20latest%20365%20version%20of%20Excel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20UNPIVOT(array%2C%20item%2C%20year)%0A%0Awhich%20is%20a%20named%20version%20of%0A%0A%3D%20LAMBDA(arr%2CItm%2CYr%2C%0A%20%20%20%20LET(%0A%20%20%20%20%20%20m%2C%20ROWS(arr)%2C%0A%20%20%20%20%20%20n%2C%20COLUMNS(arr)%2C%0A%20%20%20%20%20%20k%2C%20SEQUENCE(m*n)%2C%0A%20%20%20%20%20%20YearLst%2C%20INDEX(Yr%2C%201%2BMOD(k-1%2Cn))%2C%0A%20%20%20%20%20%20itemLst%2C%20INDEX(Itm%2C%201%2BQUOTIENT(k-1%2Cn))%2C%0A%20%20%20%20CHOOSE(%7B1%2C2%2C3%7D%2C%20itemLst%2C%20YearLst%2C%20ELEMENT(itemLst%2C%20YearLst)%20)%20)%0A%20%20)(array%2C%20item%2C%20year)%0A%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20key%20elements%20of%20the%20calculation%20are%20the%20index%20'k'%20numbering%20the%20output%20array%20and%2C%20from%20that%2C%20the%20MOD%20and%20QUOTIENT%20formulae%20that%20identify%20the%20row%20and%20column%20of%20element%20required%20from%20the%20array.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20should%20probably%20convince%20you%20to%20use%20PQ%20but%20it%20might%20be%20worth%20knowing%20other%20possibilities%20exist.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello, 

I have a panel data table. The value of an item is recorded each year. The column has values corresponding to the year ( table 1). So, there are 11 years and 11 different columns. I want to have only 2 columns, all years in 1 column (table 2). Simple transpose doesn't work. I also tried sumifs but didn't succeed. Please advise.

5 Replies
Hi

The Power Query Unpivot Other Columns function is perfect for this

Apologies for the music choice https://youtu.be/2c06jmrAb3I

Wyn
MVP
UTC + 8

@Pussyk 

As Mr. Wyn Hopkins  said, Power Query is the most suitable tool for this.

Here is some information and help for the first steps from Microsoft.

Combine data from multiple data sources (Power Query)

https://support.microsoft.com/en-us/office/combine-data-from-multiple-data-sources-power-query-70cfe...

 

* Knowing the Excel version and operating system would also be an advantage.

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

@Pussyk 

Unpivoting tables is core functionality of Power Query. 

It is also possible to effect such a transformation using formulas but that involves detailed messing about with row and column indices.  It is most elegantly performed in the latest 365 version of Excel.

 

= UNPIVOT(array, item, year)

which is a named version of

= LAMBDA(arr,Itm,Yr,
    LET(
      m, ROWS(arr),
      n, COLUMNS(arr),
      k, SEQUENCE(m*n),
      YearLst, INDEX(Yr, 1+MOD(k-1,n)),
      itemLst, INDEX(Itm, 1+QUOTIENT(k-1,n)),
    CHOOSE({1,2,3}, itemLst, YearLst, ELEMENT(itemLst, YearLst) ) )
  )(array, item, year)

The key elements of the calculation are the index 'k' numbering the output array and, from that, the MOD and QUOTIENT formulae that identify the row and column of element required from the array.

 

That should probably convince you to use PQ but it might be worth knowing other possibilities exist. 

@Peter Bartholomew , you missed ELEMENT()

@Sergei Baklan 

Just a glorified INDEX but specific to a particular array

= LAMBDA(itm,yr,
    LET(
    r0, XMATCH(itm, item),
    c0, XMATCH(yr, year),
    INDEX(array, r0, c0) )
    )

The intention is that the Lambda function should be the Name the user knows the array by and the reference within the formula is to the range that the array occupies.   That gives a more standard function notation than the INDEX formula.