transcript

excelisfun - Excel Magic Trick 1118: MODE for Text Values, Extract Word That Occurs Most Frequently

Thumbnail of the video “excelisfun - Excel Magic Trick 1118: MODE for Text Values, Extract Word That Occurs Most Frequently”
Download Markdown
Community upload. AI output has not been independently verified.

Welcome to Excel Edge trick number 1,118. Hey, if you want to download this workbook, click on the link below the video. Hey, we got to talk about modes and we need to look through a column of text values and find the one that occurs most frequently. The mode is exactly that calculation. Which one occurs most frequently? Now, back in Excel magic 592, I did a formula on this, but our awesome online Excel teammate Bill, and I can never pronounce his name, Sz YSC, came up with a great formula solution that is much easier than the one I did.

Now, let's talk about the mode, the mode function. And we will look at the mode and the mode malt, which is multiple modes. These functions require numbers. You actually have to throw numbers into them and they tell you which one occurs most frequently. So often we already have our categories here. And so we have text. We can match it to text with count if function and count for each category. And I'm going to use the count ifs with an s. I like count ifs, sum ifs, average ifs because the screen tips are easier to understand. We're going to take our whole criteria range. I'm going to click in the top cell, control shift down arrow, F4, comma, and then left arrow to get that relative cell reference. Control enter. Double click and send it down. So, we can count and see, oh, the good category is the one that occurs most frequently. Therefore, it is the mode.

However, what if you wanted a single cell formula to just look through here, skip over all of this and just pull out the word, the one that occurs most frequently. Well, we're going to have to do some formula trickery here because the mode can't do it directly. If there was some way we could take this text data and convert it to numbers, then we could use the mode. So the function we're going to use to convert these text items to numbers is the match function.

Match function, we usually give it a lookup value. Say we gave it the word somewhat and we tell it to look through this whole column. It would report the relative position because somewhat is the fourth item in this list. But check this out. We're going to do what's called a function argument array operation. That argument is expecting a single value, but we're going to give it every single value. Control shift down arrow F4. Now we type a comma and then we're going to put for the lookup array the entire range. Again, control shift down arrow F4, comma, the match type, we have to put zero. Not only is it not sorted, but when there's duplicates, we only want to pick out the first occurrence and zero exact match will do that.

Now, what is going on with this? What's happening here is this is a function argument array operation. That argument lookup value is usually expecting a single value. We just gave it a whole column of values. That means match will spit out a whole column of answers. Get it? Lookup value. It'll give me an answer for each item in this column. the relative positions. Let's highlight it and F9 to see what this evaluates to. That is beautiful. We have gone from text values to numbers. One means okay is in the first position. Two means good is in the first position. And look at that because we did exact match zero. Anytimes it finds another good, it's only going to report the first position.

Now two things about this. One is now we have numbers. The mode will understand it. And later when we get to looking it up, whichever one occurs most frequently, it will also tell us the position. Ctrl Z. Now I'm going to wrap this in the mode function. Now there is mode. This is the old mode which only finds if there's one mode or the first mode if there's multiple ones. Mode single and mode. They came in in 2010. In Excel, single is exactly like mode. I'm going to use mode just because it's easier easier. Later, we'll look at this mult for multiple. All right. So, mode around this. You're not going to believe this. When we highlight this and F9, it's now going to report the position of the one that occurs most frequently. Now, we know it's good. Ctrl Z.

We can slap that answer into a lookup function. index the array will be the entire column. Control shift down arrow F4 comma. So these are the values we want to look up and mode and match with this function argument array operation will return the relative position to row number. And you're not going to believe this. This does not require control shift enter. That is a function argument array operation. Normally we have to use control shift enter. And I'm not even sure why the mode is mode is doing it. In my book control shift enter about array formulas, I talk about mode and some of the other official array functions. They can if you put them into other functions, it doesn't require control shift enter. But this mode is not an array function. So I'm not quite sure what's going on here. I tried putting it all over the place. not next to the data set because sometimes you'll get an answer due to implicit intersection. Usually when you put an array formula outside, meaning not next to the data set, it gives you a value error. But watch this. Enter. And it got it. And you can try this. Move this other places and it's still working. So I'm not quite sure what's going on there, but boom, we got our answer. That is a beautiful formula. Here is a count if just to confirm that in fact it worked. So that is the amazing formula uh that Bill gave us.

Now let's look at a couple other examples. Sometimes you have mixed data and then we want to see what to do when you have multiple modes. Actually the formula for looking up the mode from mixed data is going to be exactly the same except for one twist. So there's our lookup values. Then I'm going to use mode. And inside of mode I'm going to use match. And I'm going to highlight for the lookup value. F4 that same range, same range again for lookup, comma, zero. Close parenthesis. Close parenthesis. Close parenthesis. Now let's check this out. If I were to go inside the mode, click on the number one, and hit F9, there's an NA for that empty cell. That is going to cause a problem. If I hit enter, it's just not going to work. So, our goal is to dump this into the mode. But we have not only an NA, but we also have a number. So, we want to do a test. We're going to use the if function to filter that resultant array. Z. What am I after? I'm after text. So, watch this. I'm going to put if and we're going to do a function argument array operation here on the logical test. And this formula will require control shift enter because whether or not you have to use control shift enter in array formulas is often determined by the actual function argument and this one requires it no matter what. Now we need a logical test that can filter these match values. So we're going to use is text the value highlight every single value. Now we're going to get a true and false for each one of those data types. I'm going to hit F4, close parentheses. So the logical test has is text, comma. Those would be the values of true. But let's check this out right here. I'm going to click on logical test. F9. Notice true, false, false, true to true. So those two falses will filter out the empty cell and the five. Control Z. And the match of course will be the values that are getting filtered. Now I want to come to the end here to the match. And notice I should type a comma and put a false. But if you leave that argument out, meaning the value of false argument out, it'll just put falses in, which is exactly perfect. So I'm going to close parenthesis. And now I want to go see what in the world if is text and match are delivering to the mode. F9. There we have it. The actual numbers that we want or the relative positions. And there are the two falses. The beautiful thing about many aggregate functions is they're programmed to ignore logical values like true and false. So it'll ignore those. Controll Z. Now I if I hit enter here, it's going to give me an NA. If the formula was up here, you get a value error. That should have happened up here, but the mode was handling it pretty well. So no problem. F2. That means we have to tell Excel that we're doing an array formula by using control shift and enter. Now when you do control shift enter, it's you telling Excel this is an array formula. When you come up to the formula bar, you can see those curly brackets. That's Excel telling you it understood. All right, so that seems to be working there.

One last example. What if you had multiple modes? And we'll change the data later and check this out. Well, we can use the modem malt for multiple. And we're going to do our same trick. We're going to put all of the match values into the lookup value. F4, then we're going to put it into the lookup array. F4, 0, close parenthesis, close parenthesis. Now, the match inside of here. F9. Bunch of numbers. But notice there's 1, two, three ones. One, two, three, fours, one, two, three, five. So, it's a three-way tie for the ones that occur most frequently, those relative positions. So, control Z mode. It just looks through and reports a unique list of the ones that occur most frequently. Now, as we copy our formula down, if we're trying to extract, since we have multiple items, we're going to have to do some lookup formula. We're going to need relative position 1, four, and then five. As we copy this down, controll Z. Actually, before we do that, let's count because we're going to have a cell at the top that looks through here and tells us how many modes there are. We can use count. Count will count numbers. And again, this mode will handle that array calculation. And so, we'll count with simply enter. So, we know there's three of them. I don't think I copied this. Ctrl C because we're going to use this. I would like to extract as I copy down each one of those relative positions. I'm going to use the small function.trlv into that array. And now I want to copy as I go down the first, second, and third values that the modem is reporting. All right, you ready? Control enter. Double click and send it down. So now it's got the relative positions. I can put it into index F2 index highlight all the values F4 comma and then the row number has that small extracting from the modem malt each new relative position as we copy the formula down controll enter double click and send it down.

Now I'm going to use the if function to turn that off so as we change this data this will update and not show me errors. I'm going to say if this number of modes is greater than our count F4, then that's the logical test. That's a single logical test, right? Then what do I want? Double quote double quote. That's a null text string that will show nothing. Otherwise, run the formula. This will not require control shift enter. That's a single true or false there, not an array. this uh mode holds that match. Simply control enter double click and send it down. Now if I come over here and change this to something now we have only two. Ctrl Z.

All right, that was a lot about extracting text values when you have modes. Here we had multiple modes. Here we had some mixed data including empty cells and we wanted text. And then this amazing formula from Bill that put the match inside of the mode.