Transposing Data with INDEX
So carrying on with my little scenario here, the Accountant storms across to your desk and says “What are you doing, this isn’t a report – give me a FY report with Jul 17 to Jun 18 month and sales across the page and do it smartly!”
Digressing because it’s relevant to below – have I told you I love the INDEX function? It is a non volatile formula meaning its light on performance usage but it’s so powerful. I urge any budding Excel Power User to learn to use INDEX and its natural buddy MATCH so it’s second nature because it gives you great power over your spreadsheeting. See my earlier posts on this topic Why I like INDEX + MATCH and INDEX, Whats the Big Deal? You can pluck any number from anywhere on the grid to anywhere you want with INDEX / MATCH. Think of INDEX as your never tiring, always faithful golden retriever who goes bounding off to get whatever you point at and get it for you all day long, without tiring. I know people like VLOOKUP to do some of what I am talking about but INDEX + MATCH is more versatile and reliable and it’s easy to learn. I hardly ever use VLOOKUP now unless its for clients who prefer it because they know which is fair enough too.
So again back to my scenario, yes you could copy, then paste special, transpose values only. But hey I am a data analyst and anything I do that I probably have to do again, I am going to automate. Automate or die should be your mantra.
So I get cracking – I add a data validation in G4 of the date column so I can have a dynamic starting point. If you were pushed for time G4 could just simply have 01/07/17 entered directly. I went the data validation route because next time my Accountant boss might want a report with 2 year’ s sales on a calendar year basis so I can easily choose another starting point in the validation dropdown. With this starting date to my data set, we can use formulas to give us the dates we want using DATE function and then our INDEX formula can use these dates to to go and get the sales pertaining to the dates I want. Now I am assuming we want to report consecutive months in this type of report. So to get the months to increment by 1 across the page – I use the relative DATE formula in H4 =DATE(YEAR(G4),MONTH(G4)+1,DAY(G4)) – basically I am leaving the YEAR and DAY alone but incrementing the MONTH by one. Copy this across and of course the it will increment by 1 month. Now I use my INDEX / MATCH combo formula:
=INDEX($B$4:$C$24,MATCH(G4,$B$4:$B$24,0),2) and it uses the date in G4 in the MATCH function within the vector $B$4:$B$24
to return the position of the date and then return the corresponding value from the 2nd column within the array $B$4:$C$24 defined in the first part of the function. You could give the array and vector range names if you want. Also would make the array $B$4:$C$24 a n Excel Table so it’s dynamic for future data. Anyway this is a simple example – copied across the formula effortlessly returns the corresponding date’s sales.