Welcome to Excel Magic Number 1425. If you want to download this Excel workbook file so you can follow along, click on the link below the video. We've got two videos in a row that we're going to do on this sheet, and the first one is how to use the INDEX function and Number Incrementor X to convert a two-way table to a single-column table.
Now I'm going to temporarily hide columns K to M. I highlight them, right-click, and hide. There are multiple ways to take each one of these columns and put them into a single column. We could use Power Query, we could use Paste Special, but I want to use some formulas because anytime anything changes here, I don't want to mess around with refreshing. I want the formula to instantly update.
Actually, I've got to show you this trick if you're just doing this as a one-time thing. Watch this. I'm going to highlight and press Ctrl+C, then C to open up the clipboard, and then I'm going to highlight each column and press Ctrl+C. In fact, watch: right arrow, Control+Shift+Down, Ctrl+C, right arrow, Control+Shift+Down, Ctrl+C, right arrow, highlight down, Ctrl+C, and I'm going to do that for each one. Notice as I copy each column, they're loaded up here. Now I can simply come over to the side somewhere, full list, Enter, and then click Paste All, and instantly I have converted that into a single table.
But again, the point of this video is that I want this to be dynamic. Anything changes here, I want it to update here. Now we have 8 columns and 40 rows. If we're thinking about copying a single formula down, it has to go first row, first column; first row, second column; first row, third column; and when it gets down to the second row, second row first column, second row second column. So inside our formula, as we copy down, I need to go 1, 1, 1, 1, 1, 1, 1, 1 eight times, and then 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8.
For the INDEX function, I'm going to build the row element that will create the pattern 1, 1, 1, 1, 2, 2, 2, 2, and then the column pattern off to the side. Any time we're using Number Incrementor X, we're going to use the ROWS function with an expandable range. I'm going to put the formula in N7, so I'll type $7:7 as an expandable range, with ROWS counting how many rows there are, from 7 to 7. That's 1. Control+Enter, and when I copy it down and come to any subsequent cell, we can see the 7 was locked here but not here, so here it's counting how many rows there are, 6.
Now I want 1s, then 2s, eight times each. Watch this: I'm going to divide that by 8. Control+Enter, double-click, and send it down. Look at that: it goes numbers almost up to 1, then 1, numbers almost up to 2, and 2. With the active cell at the top of the highlighted range, I hit F2, and I simply need to round up to the integer. I come to the number of digits, which is 0, meaning round to the nearest integer. Control+Enter populates that formula all the way down. That's the pattern for eight 1s, eight 2s, and so on.
Now I'm going to come over here and copy. Control+C, Escape, equal sign, Control+B. If we need 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, then we need to think about doing division and getting the remainder. I'm going to take this Number Incrementor X, 1, 2, 3, 4, 5, 6, 7, 8, and subtract 1. Control+Enter. Now we have 0, 1, 2, 3, 4, 5, 6, 7, 8, all the way to 16. If I divide this by 8 and ask what the remainder is, it would be 0, 1, 2, 3, 4, 5, 6, 7. Down here, the remainder of 8 divided by 8 is 0. The remainder of 9 divided by 8 is 1. That's the pattern we'll use, and the function we use to get the remainder after division is the MOD function. There's the numerator, and the denominator is 8. Close parenthesis.
This won't quite give us what we want yet. Control+Enter, double-click, and send it down: 0, 2, 7, 0, 2, 7. That's the pattern. With the active cell at the top, F2, I simply add 1, Control+Enter, to populate that all the way down.
Now I'm going to clear the clipboard. Come over here, F2, and carefully highlight, Control+C, to load it onto the clipboard. Come over here, F2, same thing, Control+C to load it onto the clipboard. Now watch this: I'm going to drag the clipboard forward over here, and here's our formula. Equals INDEX, and the entire range like this. I'll click the upper left, Control+Shift+Right Arrow, Control+Shift+Down Arrow to highlight all the way to the bottom, and then F4 to lock it. Comma. Now the row, which is rounded up, comma. Now the column, which is MOD. Those will give the proper row number and column number for extracting from our array. Come to the end and close parentheses. Control+Enter, Control+C. I'm going to use my scroll bar because I've established the bottom of the spreadsheet. Before I click on the last cell, I'm going to hold Shift and click to highlight, then Control+V, and there we have it: extracted. I move the clipboard back over here, all the way down to the bottom, and every single number is extracted. I'll hit F2 to verify, and sure enough, that looks good. Escape, Control+Home.
So in this video we saw how to take a two-way table, take each column, and convert it into a table with a single column. When we come back in our next video, we're going to see how to, from any intersecting value, look up the column headers and the row headers. We'll see you in the next video.
