Re-ordering spreadsheet

%3CLINGO-SUB%20id%3D%22lingo-sub-3219126%22%20slang%3D%22en-US%22%3ERe-ordering%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3219126%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I'm%20new%20to%20the%20forum%20and%20hope%20this%20question%20makes%20sense.%20I%20have%20a%20spreadsheet%20with%20financial%20information%20that%20I%20use%20to%20prepare%20my%20tax%20return.%20The%20rows%20are%20different%20securities.%20The%20columns%20are%20different%20types%20of%20income%20(eg%20interest%2C%20dividends%2C%20capital%20gains%2C%20etc.).%20For%20each%20security%2C%20I%20enter%20appropriate%20data%20in%20the%20relevant%20columns.%20I'd%20like%20to%20create%20a%20view%20-%20or%20a%20report%20-%20that%20would%20show%20each%20security%2C%20with%20related%20income%20types%20and%20data%20underneath%20the%20security%20name.%20In%20essence%2C%20I'm%20trying%20to%20convert%20the%20column%20data%20into%20horizontal%20rows%20under%20the%20security%20name.%20Any%20ideas%20how%20I%20could%20accomplish%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3219126%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3219828%22%20slang%3D%22en-US%22%3ERe%3A%20Re-ordering%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3219828%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1319255%22%20target%3D%22_blank%22%3E%40guywe%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eaccording%20to%20your%20description%2C%20this%20sounds%20like%20a%20perfect%20task%20for%20Power%20Query.%20You%20would%20need%20to%20load%20your%20table%20into%20Power%20Query%20and%20there%20is%20a%20transformation%20type%20called%20%22unpivot%20columns%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20your%20example%2C%20you%20would%20select%20the%20column%20with%20the%20securities%20and%20then%20upply%20the%20transformation%20%22Transform%20%7C%20Unpivot%20Columns%20%7C%20Unpivot%20other%20columns%22%3C%2FP%3E%3CP%3EThis%20will%20convert%20all%20the%20other%20columns%20into%20rows.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3219942%22%20slang%3D%22en-US%22%3ERe%3A%20Re-ordering%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3219942%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1319255%22%20target%3D%22_blank%22%3E%40guywe%3C%2FA%3E%26nbsp%3BExcel%20for%20the%20Mac%2C%20unfortunately%2C%20does%20not%20support%20the%20feature%20described%20by%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F48469%22%20target%3D%22_blank%22%3E%40DTE%3C%2FA%3E%26nbsp%3Byet.%20But%20if%20you%20are%20an%20MS365%20subscriber%20or%20have%20Excel%202021%20you%20could%20use%20a%20LAMBDA%20function%20to%20unpivot%20the%20data%20for%20you.%20It's%20demonstrated%20in%20K3%20in%20the%20attached%20file.%20I%20picked%20it%20up%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3Bno%20too%20long%20ago%20and%20tweaked%20it%20a%20little%20bit.%20Perhaps%20you%20can%20use%20it%20on%20your%20own%20data%20and%20create%20the%20reports%20you%20need%20from%20this%20tabular%20(unpivotted)%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3220317%22%20slang%3D%22en-US%22%3ERe%3A%20Re-ordering%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3220317%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Riny%3C%2FP%3E%3CP%3EIf%20you%20are%20getting%20involved%20with%20Lambda%20functions%2C%20would%20you%20like%20to%20see%20some%20utilities%20I%20have%20experimented%20with%3F%26nbsp%3B%26nbsp%3BOne%20reads%20a%20data%20item%20from%20an%20arbitrary%20representation%20of%20a%20multidimensional%20array%2C%20using%20the%20Lambda%20function%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%3D%20DATA%CE%BB(i%E1%B5%A3)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ewhich%20takes%20as%20its%20argument%20an%20array%20of%20indices%2C%26nbsp%3Bi%E1%B5%A3%20(in%20hindsight%2C%20I%20probably%20should%20have%20used%20separate%20parameters%20for%20each%20dimension%20but%20that%20would%20mean%20additional%20steps%20in%20the%20calculations).%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ETo%20be%20able%20to%20read%20a%20value%20back%20from%20any%20layout%20of%20data%20is%20useful%2C%20but%20I%20have%20also%20written%20functions%20that%20generate%20row%20and%20column%20arrays%20of%20such%20indices%20to%20allow%20the%20data%20to%20be%20repivoted%20(or%20aggregated%20by%20addition)%20at%20will.%26nbsp%3B%20One%20option%20is%20to%20create%20a%20pivot-table%20normalised%20form%20of%20the%20users%20data.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI%20have%20made%20a%20start%20with%20putting%20the%20Lambda%20functions%20up%20on%20GitHub%20as%20Gists%20but%20the%20process%20is%20completely%20alien%20to%20me%20(I%20have%20received%20some%20advice%20but%20I%20don't%20think%20my%20advisor%20realises%20the%20level%20of%20profound%20ignorance%20I%20can%20bring%20to%20the%20table).%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgist.github.com%2Fpbartxl%2F04584dd9a9e8fe9c61a10511c78f390c%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMultidimensional%20Array%20Representation%20(github.com)%3C%2FA%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI%20have%20also%20attached%20the%20workbook%20that%20demo's%20the%20functions%2C%20though%20I%20would%20not%20claim%20to%20have%20got%20to%20the%20point%20of%20the%20workbook%20being%20self-evident.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F201398%22%20target%3D%22_blank%22%3E%40Bill%20Jelen%3C%2FA%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F320924%22%20target%3D%22_blank%22%3E%40cuong%3C%2FA%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3220338%22%20slang%3D%22en-US%22%3ERe%3A%20Re-ordering%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3220338%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3BWill%20study%20with%20great%20interest!!%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, I'm new to the forum and hope this question makes sense. I have a spreadsheet with financial information that I use to prepare my tax return. The rows are different securities. The columns are different types of income (eg interest, dividends, capital gains, etc.). For each security, I enter appropriate data in the relevant columns. I'd like to create a view - or a report - that would show each security, with related income types and data underneath the security name. In essence, I'm trying to convert the column data into horizontal rows under the security name. Any ideas how I could accomplish this?

7 Replies

Hi @guywe 

 

according to your description, this sounds like a perfect task for Power Query. You would need to load your table into Power Query and there is a transformation type called "unpivot columns".

 

In your example, you would select the column with the securities and then upply the transformation "Transform | Unpivot Columns | Unpivot other columns"

This will convert all the other columns into rows.

@guywe Excel for the Mac, unfortunately, does not support the feature described by @Martin_Weiss yet. But if you are an MS365 subscriber or have Excel 2021 you could use a LAMBDA function to unpivot the data for you. It's demonstrated in K3 in the attached file. I picked it up from @Peter Bartholomew no too long ago and tweaked it a little bit. Perhaps you can use it on your own data and create the reports you need from this tabular (unpivotted) data.

 

 

@Riny_van_Eekelen 

Hi Riny

If you are getting involved with Lambda functions, would you like to see some utilities I have experimented with?  One reads a data item from an arbitrary representation of a multidimensional array, using the Lambda function

   = DATAλ(iᵣ)
which takes as its argument an array of indices, iᵣ (in hindsight, I probably should have used separate parameters for each dimension but that would mean additional steps in the calculations).
To be able to read a value back from any layout of data is useful, but I have also written functions that generate row and column arrays of such indices to allow the data to be repivoted (or aggregated by addition) at will.  One option is to create a pivot-table normalised form of the users data.
 
I have made a start with putting the Lambda functions up on GitHub as Gists but the process is completely alien to me (I have received some advice but I don't think my advisor realises the level of profound ignorance I can bring to the table).
I have also attached the workbook that demo's the functions, though I would not claim to have got to the point of the workbook being self-evident.
 
 

@Peter Bartholomew Will study with great interest!!

Thanks @Martin_Weiss . I think this approach should work, although still need to navigate my way through this! (I believe Power Query functionality is indeed available to me as a MS365 subscriber). Appreciate the guidance - thanks again!

Hi Riny, thanks. While the output of your spreadsheet is precisely what I'm seeking to achieve, Lamda functions are beyond my current capabilities! I will start off trying to use the Power Query functionality which is indeed available to mean my Mac as a MS365 subscriber. Appreciate your help - thank you!

@guywe PQ is NOT available on the Mac to the extent that you need it. You can connect to a workbook or a TXT/CSV file and import them. That's it. No more PQ functionality, unless you dive into quite cumbersome VBA solutions. Nothing you would want to get involved with, I believe. And you don't really need to understand the LAMBDA. It works like a regular function. The only difference is that the "function" exists only in the workbook as a named formula.

 

=UNPIVOT(data_range, column_header, row_header)