SOLVED

Transpose rows and join with row header using formula

%3CLINGO-SUB%20id%3D%22lingo-sub-2948290%22%20slang%3D%22en-US%22%3ETranspose%20rows%20and%20join%20with%20row%20header%20using%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2948290%22%20slang%3D%22en-US%22%3E%3CP%3EHi!%3C%2FP%3E%3CP%3EI%20need%20to%20use%20a%20formula%20(not%20macro)%20to%20transpose%20a%20table%20and%20return%20a%20table%20based%20on%20the%20row%20header%20and%20each%20individual%20column%20value.%3C%2FP%3E%3CP%3EOptionally%20a%20textjoin%20of%20the%20combination%20cold%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20appended%20an%20example%20sheet%20with%20the%20source%20data%20in%20A1%3AD4%20and%20example%20output%20in%20F1%3AG8%20with%20the%20textjoin%20option%20in%20I2%3AI8.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20source%20data%20may%20grow%20downwards%20but%20the%20number%20of%20columns%20is%20static.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20using%20Office%20365%20with%20an%20E5%20licence.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBR%20%2FMats%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2948290%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2948338%22%20slang%3D%22en-US%22%3ERe%3A%20Transpose%20rows%20and%20join%20with%20row%20header%20using%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2948338%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1197511%22%20target%3D%22_blank%22%3E%40MHulten%3C%2FA%3E%26nbsp%3BI%20would%20like%20to%20suggest%20PowerQuery.%20Unpivot%20the%20data%20on%20the%20left%20and%20merge%20the%20two%20relevant%20columns%20to%20one%2C%20with%20a%20hyphen%20as%20the%20delimiter.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2950266%22%20slang%3D%22en-US%22%3ERe%3A%20Transpose%20rows%20and%20join%20with%20row%20header%20using%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2950266%22%20slang%3D%22en-US%22%3EI%20haven%E2%80%99t%20used%20PowerQuery.%3CBR%20%2F%3EThe%20intention%20is%20to%20distribute%20this%20as%20a%20template.%20I%20can%E2%80%99t%20have%20any%20inbuilt%20dependencies%20other%20than%20the%20version%20of%20Excel%20that%20is%20distributed%20with%20the%20E5%20license.%3CBR%20%2F%3EWould%20this%20work%20with%20PowerQuery%3F%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi!

I need to use a formula (not macro) to transpose a table and return another table based on the row header and each individual column value.

Optionally a textjoin of the combination cold work.

 

Note that the source data may be defined as a table, range, or stay as "normal" data in the sheet based on what would be convenient.

 

I have appended an example sheet with the source data in A1:D4 and example output in F1:G8 with the textjoin option in I2:I8.

 

 

The source data may grow downwards but the number of columns is static.

 

I'm using Office 365 with an E5 licence.

 

BR /Mats

7 Replies

@MHulten I would like to suggest PowerQuery, i.e. not a formula. Unpivot the data on the left and merge the two relevant columns to one, with a hyphen as the delimiter.

Example attached.

I haven’t used PowerQuery.
The intention is to distribute this as a template. I can’t have any inbuilt dependencies other than the version of Excel that is distributed with the E5 license.
Would this work with PowerQuery?

@MHulten Well, as long as your users aren't using a Mac, this could work for all. From Excel 2016, PQ is included in Excel. In Excel 2013 it's an add-in. If you could accept teaching you users to press "Refresh" every now and then it should work. PQ is much more user friendly and flexible than complicated formulae.

 

A good introduction to PQ in the link below:

https://exceloffthegrid.com/power-query-introduction/ 

best response confirmed by MHulten (Occasional Contributor)
Solution

@MHulten 

That could be

=LET(
  rws,     ROWS(Table1),
  cls,     COLUMNS(Table1),
  k,       SEQUENCE(rws*(cls-1)),
  i,       MOD( k-1, cls-1)+2,
  j,       INT( (k-1)/(cls-1)) +1,
  postfix, INDEX( Table1, j, i ),
  all,     IF( ISBLANK(postfix), "",   INDEX( Table1, j,1 ) & "-" & postfix),
  FILTER(all, all<>"") )
Looks really interesting, but due to time constraints I need to stick to technologies I'm familiar with.
Checking out PQ will definitely be on my to-dos though.
Works like a charm! Thank you!
Now... could you please offer an explanation...

@MHulten 

Not sure which kind of explanations are required, it depends on how familiar you are with dynamic array functions.

 

First one is LET function (microsoft.com) which combines our calculations in one block.

SEQUENCE() generates list of indexes for data part of the table, i and j extracts from it column and row number related to each index.

 

With INDEX() we generate for every index some value depends on related column/row number, finally FILTER() all values with empty texts.