We have **3 fields** and **3656 rows** of data.

Look carefully at the data below. **Can you see what the challenge is?**

For each ‘CustomerID’ we need to add up the ‘Sales’ amount per month. **But, we have data at the day level not the month level. We need to aggregate it up to the month level.**

Get The Excel File **here** and follow along!

This is my **favorite solution**. Why? It’s **so simple and quick!**

Create a Pivot Table with ‘Customer ID’ in ‘Rows’, ‘Date’ in columns and ‘Sales’ in ‘Values’ area. Note that you might have to group ‘Date’ by month. We now have the monthly aggregated total for each customer. Then add a MAX function to get the largest aggregated amount.

It’s almost perfect but the pivot would need to be refreshed if you add or change data and you might have to adjust the range of the MAX function if your Pivot Table expands.

Here is Mike’s array (note that AGGREGATE function can handle arrays without control shift enter).

**=AGGREGATE(14,4,SUMIFS(F8:F3663,E8:E3663,A8:A88,D8:D3663,**

**“>=”&EDATE(B3,{0,1,2,3,4,5,6,7,8,9,10,11}),D8:D3663,**

**“<=”&EDATE(EOMONTH(B3,0),{0,1,2,3,4,5,6,7,8,9,10,11})),1)**

**Why such a complex formula?** If you don’t like the pivot table taking up space in your sheet and you want a single cell solution then all the steps have to be done inside of a single formula. Yes, this solution is dynamic (the Pivot Table solution requires a refresh if data changes) but is it really worth it?

For me, I love arrays, but this formula is definitely a stretch. Nevertheless, I like it because I want to learn more about the versatile and powerful AGGREGATE function. I haven’t yet become comfortable enough with the AGGREGATE function to be able to quickly use it.

I was thinking “**Is there possibly an easier to understand multiple step dynamic solution?**” You’ll find my solution in sheet ‘Kevins Helper Solution’.

Solution Steps

- Column Q helper truncates ‘Date’ values to start of month (i.e. 2016-07-28 becomes 2016-07-01)
- Columns C to N calc monthly total per ‘CustomerID’. Formulas in row 6 dynamically create start of month values. Sumifs starting in row 8 calculate ‘Sales’ per ‘Month’ and ‘Customer ID’
- Now that we have all the monthly totals per ‘CustomerID’ the simple MAX function in cell T5 calculates the final answer!

Yes, this method requires a lot of cells for the formulas but some may prefer this as it’s easier to audit compared to the array solution. However, if we had to do this for every month over many years (not just 1 year as we have here) then we would need a ton of helper columns and it would probably not be a good solution.

**9 times out of 10 Mike’s Pivot Table and Max formula should win!** Super quick and easy to explain. The one formula array solution is for Excel power user’s and my helper column solution would work for non power users that want a dynamic solution that they can audit and understand.

I’ve created this matrix to compare the solutions based on several factors. Note that there are comments in most cells that you can see if you download my Excel file.

**What solution do you prefer and why? Can you think of another solution?**

My name is Kevin Lehrbass. I live in Markham, Ontario, Canada. I’ve been studying, supporting, building, troubleshooting, teaching and dreaming in Excel since 2001. I’m a Data Analyst at McKinsey & Company.

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy learning Spanish, playing Chess, hanging out with Cali and Fenton and reading Excel books

]]>

Before we look at this challenge, don’t forget that we can’t create the ideal solution unless we’ve asked the right questions. Is this a one time task? How long would it take to complete manually? Should the solution be easy to understand? What version of Excel is being used? Can we re-arrange the data and then solve it? If it’s a long term solution, can we change the data input structure? (normalized format)

Follow along with Leila’s **Excel file** (modified with solutions from me, Wasif Mustafa and Oz du Soleil).

Each ‘App’ listed in column H is found somewhere in columns B, C, or D. When found, we want to return the column header (the ‘Division’).

**One formula solves it!** Complex formulas for some but an expert can create it in a couple of minutes.

Leila’s Sumproduct formula **=INDEX($B$4:$D$4,,SUMPRODUCT(($B$5:$D$45=H5)*(COLUMN($B$4:$D$4)-COLUMN($A$4))))**

My Array formula **=INDEX($A$4:$D$4,MIN(IF(H5=$B$5:$D$45,COLUMN($B$5:$D$45),””)))**

Instead of 1 complex formula, what about breaking the solution down into easier to explain pieces? Some people have no interest in learning complex formulas but can follow carefully documented steps. **I initially missed that fact that there can sometimes be multiple ‘Apps’ listed per row. This made it more challenging.** It might not be an ideal solution but I got it to work!

Advanced Excel users might roll their eyes at a multi-step solution. Don’t forget that casual Excel users prefer understandable solutions.

**1. helper** (concatenate all text per row) **=”,”&B5&”,”&C5&”,”&D5&”,”**

**2. get helper** (lookup App, get helper value) **=INDEX($E$5:$E$45,MATCH(“*,”&H5&”,*”,$E$5:$E$45,0))**

**3. Left of ‘App’** (display what’s to the left of ‘App’ in step2) **=LEFT(I5,FIND(H5,I5)-1)**

**4. Count commas** (count the commas in step3) **=LEN(SUBSTITUTE(J5,SUBSTITUTE(J5,”,”,””),””))**

**5. Get Answer** (index column headers using step4 value) **=INDEX($B$4:$D$4,K5)**

Each mini step can be explained to the casual Excel user.

The data is not normalized so this makes any solution more challenging. Some people like to present the data in a matrix format but analyzing that data afterwards is often more challenging.

We could **normalize the data quickly using the Pivot Table ALT D P** trick. Once it’s normalized the **index & match functions quickly solve it** for us! If more data is added, it could be added in the new normalized structure. This way** we don’t have to normalize the data or refresh a query ever again!**

If you have Get & Transform (aka Power Query) you can create a simple query that will normalize the data. Then, a quick INDEX & MATCH formula solves it! End users can add more data in the original structure but they will need to refresh the query. After my video I added this solution in my Excel file and later on **Oz du Soleil** created a **video** as well. Oz loves Get & Transform!

This idea came from a YouTube viewer **Wasif Mustafa**. He sent me his solution and it’s great! Use a match formula like this: **=MATCH(H5,$B$4:$B$45,0)** for columns B, C and D. Then this IF statement **=IF(ISNUMBER(M5),”Productivity”,IF(ISNUMBER(N5),”Games”,IF(ISNUMBER(O5),”Utility”,”App not found”)))** in column I to get the answer!

I modified **Wasif**‘s idea and came up with another variation of this. **Oz du Soleil had a “3 helpers in 1” idea** along with an INDEX function (Oz used INDEX function not VLOOKUP!!!).

Currently, we have only 40 rows of data and we have 12 apps to find. We could use Excel’s Find feature to locate each ‘App’ and then copy/paste the column header. Not an exciting solution but it’s a quick and simple “**Get ‘er done**” solution.

Over the years, I have met a couple of VBA programmers that “think in code” like I think in formulas. They could easily create code to solve this. It would take me a long time.

Like in all cases, understand the requirements carefully (I initially missed that there can be more than 1 ‘App’ per row). Yes, listening is important but ask questions too! Then, before building the solution consider all relevant factors. Build the solution and teach it back to the person that you’re helping.

Thanks to **Leila Gharani** for the interesting puzzle and sumproduct solution, thanks to **Oz du Soleil** and **Wasif Mustafa** for their awesome solutions!!

Leila’s **post**, Leila’s **video**, Leila’s **courses, **Oz’s **video**, Oz’s LinkedIn **post**.

My name is Kevin Lehrbass. I live in Markham, Ontario, Canada. I’ve been studying, supporting, building, troubleshooting, teaching and dreaming in Excel since 2001. I’m a Data Analyst at McKinsey & Company.

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy learning Spanish, playing Chess, hanging out with Cali and Fenton and reading Excel books

]]>

Let’s use population by state for the United States.

**STEP 1 ** **EXPANDING SUM FORMULA (Cumulative Sum)**

We have our original data: ‘**State**‘ and ‘**Population**‘. We add this simple formula in cell C6 **=B6+C5 ** alongside all of our data.

**STEP 2 ** **CREATE RANDOM NUMBERS**

We add this formula **=RANDBETWEEN(1,’Original Data’!$D$5) **that creates random numbers between 1 and 319451069 (total sum of the population).

**STEP 3 ** **APPROXIMATE MATCH INTO STEP 1**

We add this formula **=MATCH(A6,’Original Data’!$C$5:$C$55,TRUE) **that bins our random number back into our expanding sum. We bin by using TRUE for approximate match.

**STEP 4 ** **INDEX FUNCTION GETS OUR ANSWER**

We add this formula **=INDEX(‘Original Data’!$A$6:$A$55,B6) **The index function references our text ‘State’ values and uses the result of the match function (Step 3) to display a state.

Here is my **Excel file** (or get it **here ** from my OneDrive). Here is my **YouTube video**.

Step 1 runs alongside your original data. Drag it down further if you have more data.

Steps 2, 3, and 4 are dragged down as far as you want in sheet ‘Randomly Created Data’. If you don’t drag the formulas down very far you’ll see more variation.

Sheet ‘Pivot & Formulas to Verify’ shows how close our randomly generated data is to our original state population data.

**That’s it, we are finished!**

—————————————————————————————————————————–

But wait……

Say what? **What if you want more variation in your random data. After all, isn’t it supposed to be random??** Good point.

*Fasten your seat belts ladies and gentlemen. It’s about to get nerdy!*

**Random Variation Options**

I have extended our solution to give us these three options:

- Use original expanding range (smallest variation)
- I want some variation. Currently set to 30.0% Based on value in cell F3
- I want to add variation manually (using columns H & I)

**Option 1**: Smallest variation if we’ve dragged down the formulas far enough in sheet ‘Randomly Created Data’

**Option 2**: Type in a % value in cell F3 that will increase or decrease (it’s random) the individual state population

**Option 3**: The option to manually type in a positive or negative number to be added or subtracted to our state population

Above we see that option 2 has been selected. Randomly add or subtract a percent of each state’s population.

The randomly generated ‘State’ data in column C of sheet ‘Randomly Created Data’ is now updated. Refresh the pivot table in sheet ‘Pivot & Formulas to Verify’ to see the variation.

*Isn’t that cool?*

Here is my **Excel file** (or get it **here ** from my OneDrive) that includes the additional variation options.

Simply change the numerical values to be the same value (i.e. 1).

Or, check out these solutions from **Exceljet** and **Contextures**.

**I like**: pineapple, mushrooms, olives, coffee, chocolate mint ice cream, NBA, listening to Spanish radio, data (obviously), my dogs, playing chess, drawing nerds and listening to music on Spotify.

**Random Facts**: I’m tall but not freakishly tall unless I’m in Costa Rica for work where the average height is lower and I’m 3+ standard deviations above the average height (hence the increased stares). I met NBA legend Bill Walton at the top of a pyramid north of Mexico City. I like book stores. I have a better than average memory (according to my siblings). I am a long-suffering Maple Leafs fan (if the Red Sox and Cubs can win we can too!).

**Strange:** Before the age of 40 I had never traveled to Europe. I simply had to go! After the initial trip I then had two business trips to Europe (3 trips to Europe in about 4 years!). Blindfolded I can tell the difference between Starbucks, Tim Hortons and Second Cup coffee. I’m a decent chess player but I could never solve a Rubick’s Cube (I got four sides once). I have an abnormal obsession with Microsoft Excel (or so I’m told). In a previous job I was allowed into the computer server room to test if databases were running. I wasn’t allowed to type or touch anything so I had to verbally spell out the SQL queries to another IT person who had permission to type.

Most of us would simply stop running. Not Krista. She doesn’t give up easily. Focus, determination and grit are words that I would use to describe her.

I can remember the first time that Krista broke her leg. She was only 1 and had only just started walking on her own. I can vividly remember her with her cast. When she cried we would give her toys and play with her. When the cast came off mom told us not to hand her the toys but to set the toys a few feet away so that Krista would have to get moving again. I can remember an adult saying “**She might never walk properly**“. Ahhh, wrong!

Despite her injuries, Krista also had to pass the Canadian Olympic committee’s challenging criteria to quality for the Olympics. She trained diligently, met the requirements (**Globe & Mail article**, **Toronto Star Article**), stayed healthy and made it to the Olympics in August of 2016!

A group of us traveled down to Rio to cheer for Krista. During the race, we saw video updates on the big screen and diligently watched the ticker at the stadium. We were all so proud and relieved when we saw her enter the stadium and cross the finish line! What an incredible experience.

This was our group relaxing at Canada House after the race.

A few weeks ago I was trying to find the race data. Did she finish 34th or 35th? What was her time? 2:35:00 or 2:36:00? I finally found some data from **www.olympic.org/**

Each entry was three rows, there were logos and hyperlinks. We can’t easily analyze this data unless we re-arrange it. I thought of several ways to re-arrange the data but using some INDEX functions was the easiest (see my Excel file below). Now the data looks like this! Each row is a runner, each column is a field.

I created some Pivot Tables to answer questions like these:

- Fastest average time by country (excluding runners who didn’t finish the race)
- Percent of athletes who did not finish the marathon and those that did finish the marathon
- Average marathon time (for those that finished)

Sheet “Quartiles” calculates the quartiles (splitting runners who finished the race into four groups).

**There were triplets who qualified for the women’s marathon. Can you create a solution (1 formula or several steps) that will list all three names?**

Use the data in columns G and H of sheet “Cleanup via INDEX formulas”.

HINT: They have the same last name, their first names all start with the same letter and as you might expect they are all from the same country.

Here is my **Excel file**. or get it **here** from my OneDrive.

**HAPPY CANADA DAY! 150 YEARS TODAY!**

My name is Kevin Lehrbass. I live in Markham, Ontario, Canada. I’ve been studying, supporting, building, troubleshooting, teaching and dreaming in Excel since 2001. I’m a Data Analyst at McKinsey & Company.

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy learning Spanish, playing Chess, hanging out with Cali and Fenton and reading Excel books

]]>

You open your friend’s Excel file and discover that **some of the formulas aren’t working and include the letters XLFN** ! You call your friend but he says that everything looks perfectly fine on her laptop. Did you get too much sun? Did you eat some bad fish? Did you smoke one of Oz du Soleil’s cigars?

xlfn is a prefix added to functions that don’t exist in the version of Excel that you are using. WHAT?!?!

You have Excel 2013 and your friend has a newer version of Excel (Office 365 or Excel 2016). He uses a cool new function and sends the file to you. As you have Excel 2013 this cool new function doesn’t yet exist and you see xlfn in front of the function.

Last year I discovered David Hager’s Excel blog. He shares a lot of neat ideas. I recently saw this post: **Conditional Format Rows in List 1 that are Not in List 2**

When I opened the file I noticed that the solution wasn’t working for me. I went back to David’s post and looked at this pic:

I noticed that David used the CONCAT function. This must be a new Excel 2016 (or Office365?) function! There are a bunch of really interesting new functions but I’m still using Excel 2013.

“Remove the unsupported functions, or if possible, replace the unsupported functions with supported functions.” Also, read **this**.

Although not as easy as David’s solution we can still produce the same end result.

Here are the steps to my workaround solution:

- Use a helper formula to concatenate all values in both tables: (i.e.
**=K2&L2&M2&N2&O2 )** - Adding this
**=ISNUMBER(MATCH(A2,$J$2:$J$6,0))**shows whether or not the row is found (Cell A2 is key in table 1. Column J is key in table 2) - Add this formula inside your conditional formatting rule:
**=$B2=FALSE**

Here is David’s **Excel file** that includes my workaround solution for those that don’t have Excel 2016.

You can find David at **https://dhexcel1.wordpress.com/** and **https://twitter.com/dhExcel**

** There are so many amazing things that you can do with this powerful software**. Check out my

This is **Bill Szysz**‘s winning formula from an Excel Challenge by **excelxor.com**!

**=SUM(COUNTIF(A1:H8,{“B”,”W”}&{“P”;”N”;”B”;”R”;”Q”})*{-1,1}*{1;3;3;5;9})**

Here is Excelxor’s **challenge post** and **solution post !**

In this Excel screenshot WQ = white queen, BB = black bishop, WP = white pawn etc.

Depending on position, the pawn is the weakest piece (1 point), followed by knight (3 points), bishop (3 points), rook (5 points) and queen (9 points).

**The challenge is to calculate the numerical values of white’s pieces and black’s pieces using an Excel formula! Shortest formula wins.**

Here is the **Excel file** that I used for this post. Here is my **YouTube video**.

We could list all the pieces in a column and use a simple countif but that wouldn’t be as much fun! **The white and black pieces (i.e. BP, WP, BN, etc) are created dynamically inside of the countif formula!**

**Dynamically? Yes!** The formula criteria uses two array constants. Array constant #1 **{“B”,”W”}** “B” = Black, “W” = White, which is then concatenated with array constant #2 **{“P”;”N”;”B”;”R”;”Q”} **representing all the chess pieces (except for the King).** **

**How? Here is the trick! A comma separates the colors while semi colons separate the pieces as they go in different directions (dimensions). When they are concatenated we get all the combinations between the two sets of letters!!!**

You start with this **{“B”,”W”}&{“P”;”N”;”B”;”R”;”Q”} **and end up with this** {“BP”,”WP”;”BN”,”WN”;”BB”,”WB”;”BR”,”WR”;”BQ”,”WQ”}**

Highlight the ‘criteria’ part of the countif function and press F9 key (or Fn & F9 on a laptop)

The COUNTIF’s work is finished once the combinations between the two sets off letters are created and counted. The results (plural) of the COUNTIF are then multiplied by ***{-1,1}*{1;3;3;5;9}**

**WHAT??** First we have to **distinguish the black pieces from the white pieces** hence the **{-1,1}. **Black pieces multiplied by -1 and white pieces by 1.

Then **{1;3;3;5;9} **which goes back to **the numerical value of the pieces**. In the end we have negative numbers for black and positive numbers for white.

In the screen shot above, when we add them all up we -3. This means that black has 3 additional points worth of piece material compared to white (it doesn’t necessarily mean that black is winning). A positive number would mean that white has more material.

**For an Excel and Chess nerd like me this solution was I N C R E D I B L E !!!**

I re-created the chess board in Excel that calculates the value of the pieces. I also included a drop down list so that you can change the chess that appear on the board. This changes the answer.

This is Microsoft Excel legend Bill Szysz. Check out his **YouTube channel**.

*…the story ends here but I continued to play around with this concept…..*

Occasionally someone asks me to **create all the combinations from two lists**. There are various ways to do this:

- cartesian product in a database
- pivot table trick (
**my video**) - traditional excel formula (scroll to bottom of post)
- vba code

**Let’s have some fun and use the method that we’ve learned from Bill Szysz.**

**1. Create separate tables for each text list**

**2. Select a range of cells consisting of 4 rows and 7 columns**

**3. Type =B3:B6&TRANSPOSE(D3:D9) and press CONTROL SHIFT ENTER**

It’s a quick way to display all of the combinations but it’s not dynamic if we add more text and the text is in a block not in a single column (or row).

**1. Create separate tables for each text list**

**2. Create a counter (manual drag or via formula)**

**3. Use COUNTA functions to count text values in each table**

In cell I1 add this formula **=COUNTA(Table2[List 2])**

In cell J1 add this formula **=I1*COUNTA(Table1[List 1])**

**4. Use this formula to repeat based on the number of text values per list**

In cell H3 add this formula **=IF($G3>$J$1,””,IF($G3=1,1,IF($I2=$I$1,H2+1,H2)))**

In cell I3 add this formula **=IF($G3>$J$1,””,MOD($G3-1,I$1)+1)**

**5. This is our final formula that displays the text values!**

In cell J3 add this formula **=IF(I3=””,””,INDEX(Table1[List 1]&TRANSPOSE(Table2[List 2]),H3,I3)) **and instead of pressing ‘Enter’ like you normally would press ‘Control Shift Enter’ as this is an array formula.

Type in text directly below List 1 and List 2. This will automatically expand the table(s) and you should see the values in ‘COMBINED LIST’ (column J) expand. Note that the formula in cell J1 is the total number of combined text items. You may have to drag down the formulas if you add a lot of text to the lists.

Do you see how I used the IF function in many of the formulas above. I like to give the formula a reason to do nothing. Once we have displayed all of the ‘COMBINED LIST’ items there is no reason for the formulas to calculate anything.

This is a more traditional way to concatenate using two OFFSET functions (or INDEX functions).

**OFFSET(Table1[[#Headers],[List 1]],H3,0)&OFFSET(Table2[[#Headers],[List 2]],I3,0)**

This method also requires the counters. I guess you could argue that it’s better because it’s a bit shorter and it isn’t an array. We just use the counters to loop through each table and get a single value from each table.

**NOTE: Let’s not forget that with Excelxor’s method there was no need to make it expandable. The number of unique chess pieces is a constant and will never change. This is why the text values were hard coded inside of the formula like this:** **{“B”,”W”}&{“P”;”N”;”B”;”R”;”Q”} and there was no need to extract them.**

Why learn Excelxor’s method if it might not be the easiest method for creating a Cartesian product? **It’s important for me is to continue to expand my knowledge in Excel. The more knowledge that I have enables me to provide better and quicker solutions.** What I learned from Excelxor’s blog is amazing because it creates all the combinations inside of the formula. There have been many times when I’ve learned something new and then applied it in a practical way to help someone in Excel!

Me and my **{“B”,”W”} **dogs Cali and Fenton!

** There are so many amazing things that you can do with this powerful software**. Check out my

A group of students write a test and get a numerical score out of 100. We want to convert these numerical scores into a letter grade like A+, A, A-, B+, B, B-, etc.

Some solutions are easier if we only have grades A, B, C, D, F but often we have to include the + and – grades. It would look something like this:

Get the Excel file **here** or from my One Drive **here** (“Nested If versus Lookup Table v6.xlsx”)

How do we judge the solutions? Here are some possible factors to consider:

**Quickest**solution to create- Easiest solution to
**understand/audit** - Easiest solution to
**modify** - Quickest solution to
**calculate** - Least
**error**prone solution

**=IF(A3>=98,”A+”,IF(A3>=93,”A”,IF(A3>=90,”A-“,IF(A3>=88,”B+”,IF(A3>=83,”B”,**

**IF(A3>=80,”B-“,IF(A3>=78,”C+”,IF(A3>=73,”C”,IF(A3>=70,”C-“,IF(A3>=68,”D+”,**

**IF(A3>=63,”D”,IF(A3>=60,”D-“,IF(A3>=59,”F+”,”F”)))))))))))))**

The **nested if** is a long and time consuming formula to create but it’s relatively easy to understand. In the ‘old days’ of Excel (before Excel 2007) only 7 nested ifs were possible but now the limit 64 so this solution works nicely as there are a limited amount of grades.

**Speed to Create** if the number of grades is limited (i.e. 5 if no +- grades up to possibly 12) copy/pasting the IF and changing the values wouldn’t take that long to create. If we were binning for another reason (not grades) that had 50 groups then the IF method would be too time consuming to create. Better to use a binning table (see **Solution 3** below).

**Understand/Audit** I would have to say that it’s easy to understand. Just read the ifs from left to right. Include a default grade (“F” in this case).

**Modify** simply start defining at the top (i.e. **IF(A3>=98,”A+” **) and keep moving down.

**Calculate** The ifs, or bins, are limited so calculation speed isn’t a factor.

**Error** **What if someone enters text? It would default to an A+ !!** Why? Because every character that you can type has a number. Use the CODE function and reference a value in a cell to see how this works. What can we do? Modify this solution be adding **IF(ISTEXT(A8),””,** immediately to the right of the = . Make sure than your numbers really area numbers and not numbers stored as text!

**=IF(A3>=90,”A”,IF(A3>=80,”B”,IF(A3>=70,”C”,IF(A3>=60,”D”,”F”))))&IF(A3>98,”+”,IF(A3<59,””,IF(OR(RIGHT(A3,1)={“1″,”2″,”0″}),”-“,IF(OR(RIGHT(A3,1)={“8″,”9″}),”+”,””))))**

I found this shorter nested if formula on **David Hager’s** **blog**. David calls it “Short & Sweet” as it’s shorter than the typical nested if and it doesn’t require a mapping table.

**Speed to Create** If I lost this formula it would definitely take me much longer to re-create. Nested if that also concatenates and uses an array constant! The work of a very skilled data analyst makes this tricky and slow to create.

**Understand/Audit** It definitely takes more time to understand this formula. Data analysts will be intrigued by this clever formula.

**Modify** Although it’s challenging to understand and then modify it’s kind of fun to play with. David’s formula is a data lover’s formula.

**Calculate** We’d need to have 1000s of students to see how fast/slow this is. As this is rare, it’s not a concern.

**Error** **What if someone enters text? Read ‘Error’ in ‘Long NESTED IF’ solution above. **Be careful modifying this formula. Buy a coffee for your local data analyst and they’ll help you!

This has been my favorite solution over the years. Once I can explain the approximate match concept my experience is that people love this solution. It’s so easy to modify the bin ranges. Just remember that the numbers need to increase as you move down the column.

**Speed to Create** It’s super quick to create a mapping table and then use one of these functions: **lookup**, **vlookup** or **index/match. **Don’t forget to use approximate match! This means use TRUE as the last match type and not the more common FALSE (only use TRUE as in this case we are binning!).

**Understand/Audit** The approximate match concept might initially take time to understand but after that it’s easy.

**Modify** Changing the grade limits are super easy using this method once the approximate match concept is understood.

**Calculate** Once again, not really a factor as you would almost never have a huge amount of students (i.e. 200000 +)

**Error** With two steps (mapping table and then lookup formula) I guess there is a chance that an error can occur. Mapping table must be ordered correctly (larger numbers as you move down). The rare lookup function is probably the best (or Index/Match combo) as there is no column index number to worry about (if you hard code the column index number in a vlookup then inserting a column in the middle of the table would break the solution).

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy playing with my dogs Cali & Fenton, learning Spanish and playing Chess and reading Excel books

]]>The image below shows a 6 row and 4 column matrix of non blank and blank values.

In column G we see the extracted list of non blank entries. There are actually two challenges as we can extract the values by row or by column. In this case we see the ‘by row left to right’ result.

I’ll list Excelor’s solutions and then review mine. Excelxor’s original posts can be found **here** and **here**.

Get the Excel file **here** or **here** (One Drive) and watch my **YouTube video**.

Here is the array formula (to enter press Control Shift Enter)

**=IF(ROWS($1:1)>$F$1,””,INDIRECT(TEXT(SMALL(IF(Range1<>””,10^5***

**ROW(Range1)+COLUMN(Range1)),ROWS($1:1)),”R0C00000″),0))**

The only helper the above formula requires is this formula =SUM(COUNTIF(Range1,{“>0″,”?*”})) that counts the number of non blanks. Notice the interesting use of an array constant inside the countif.

What I learned from this solution is that **the INDIRECT function can accept a reference in R1C1 format!** If you highlight indirect’s ‘ref_text’ argument and press the F9 key to evaluate it you’ll see this: **INDIRECT(“R1C00001”,0) **The second argument, set to 0, is what tells Excel that we want to use the R1C1 (Row Column) format and not the more common cell address method.

Here is the array formula (to enter press Control Shift Enter).

**=IF(ROWS(I$1:I1)>$F$1,””,INDIRECT(TEXT(SMALL(IF(TRANSPOSE($A$1:$D$6)<>””,TRANSPOSE(10^(4+COLUMN($A$1:$D$6))*ROW($A$1:$D$6)+COLUMN($A$1:$D$6))),**

**ROWS(I$1:I1)),”R0C”&REPT(0,LEN(SMALL(IF(TRANSPOSE($A$1:$D$6)<>””,TRANSPOSE(10^(4+COLUMN($A$1:$D$6))*ROW($A$1:$D$6)****+COLUMN($A$1:$D$6))),**

**ROWS(I$1:I1)))-1)),0))**

It appears that it’s more challenging to solve when values are to be displayed by column.

My solution works for both ‘By Row’ and ‘By Column’ challenges (requires slight changes). I’m able to simplify the solution as I use helper columns. This goes against the challenge a bit but this makes the solution more understandable.

- Step 1 Add a simple counter.
- Step 2 Array formula in column J:
**=SMALL(IF($A$1:$D$6<>””,COLUMN($A$1:$D$6)+ROW($A$1:$D$6)/1000,””),$G4)**If the range isn’t blank I get the column numbers as integers. Then I add the row numbers as a decimal! I do this by dividing the row numbers by 1000! Small function then extracts the values one by one using the counter. - Step 3 In column K this
**=INT(J4)**gives us the integer which is the column number. - Step 4 In column L this
**=(J4-K4)*1000**part creates the row number using the decimal value. - Step 5
**=INDEX($A$1:$D$6,L4,K4)**Now we simply retrieve the value. Done!

In the array (Step 2 above), we just have to change this **COLUMN($A$1:$D$6)+ROW($A$1:$D$6)/1000** to this **ROW($A$1:$D$6)+COLUMN($A$1:$D$6)/1000** and voila!

It’s very easy to modify as the two solutions are almost identical (see my Excel file below).

In many cases formulas are calculating when it’s not necessary. In this case, we can count the number of non blanks and simply add an IF function like this **=IF($G4>$G$1,””,** to turn off the calculation (cell G1 counts the non blanks).

Trying to solve these challenges is: (a) a way to improve your problem solving abilities and (b) an exercise in exploring Excel functions. If you work with Excel enough you’ll sooner or later need to solve bizarre challenges and solving/studying Excelxor’s challenges is the workout that will help.

Despite years of experience working in Excel I’ll be honest that I can’t solve most of Excelxor’s challenges. Nevertheless, I enjoy reading and studying the solutions. Here are some interesting ones:

- excelxor.com/shortest-formula-challenge-6-scrabbled/
- excelxor.com/13-single-array-containing-all-entries-from-a-given-range-in-multiple-sheets/
- excelxor.com/counting-rows-where-at-least-one-condition-is-met/

*Thanks Excelxor for the amazing Excel challenges!*

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy playing with my dogs Cali & Fenton, learning Spanish, playing Chess and reading Excel books

]]>

** =IFERROR(LOOKUP(1E+100,SEARCH(tblFilterList[Filter List],[@Name]),tblFilterList[Filter List]),””)**

Watch Jon’s **video** and read his **post** to see exactly how this formula works.

Normally, when using the SEARCH function in this manner (creating an array of search values) it would be an array formula (CONTROL SHIFT ENTER instead of just ENTER).

In this case we simply press ENTER because the LOOKUP function was designed to handle an array of values. **This is why I like Jon’s formula. It reminded me that some functions can handle arrays without CONTROL SHIFT ENTER.** Note: INDEX, SUMPRODUCT and AGGREGATE functions can also handle arrays without CONTROL SHIFT ENTER.

This comment was made on Jon’s YouTube video:

Hi Jon,

Exceptional as always. Quick question though:What if we had Beachwood City, how would we be able to count all three of them, please?

It’s an interesting question and I came up with this array formula:

**=COUNT(SEARCH(tblFilterList[Filter List],[@Name])) **

This formula does require CONTROL SHIFT ENTER. Note: if a search word is found multiple times in a cell it counts as only 1.

Get the Excel file **here** (**Reverse-Filter-List-of-Items-Partial-Match (2).xlsx**) or **here** .

Jon’s **LOOKUP & SEARCH **solution works perfectly if only one search word is found within the city names. If multiple words are found then, due to the nature of the LOOKUP function’s approximate match, the last search word found is what would appear in column ‘Partial Match Filter’.

**For example: In cell A344 we find ‘Redwood City’. This contains search words ‘wood’ and ‘City’ but the last search word ‘wood’ appears in cell C344.**

If you want to prioritize the words then I would suggest changing the word order in field ‘Filter List’.

Remember Columbo? His famous line was “**Just One more thing…**” often followed by a question.

**Here’s my “One more thing”:**

What if we want to count all the occurrences of each individual search word even if it occurs multiple times in the same cell?

In column F of sheet ‘Count all occurrences of word‘ I used this array beast:

**=(SUM((LEN(CA_Cities___Wikipedia[Name])-LEN(SUBSTITUTE(LOWER(CA_Cities___Wikipedia[Name]),LOWER([@[Filter List]]),””)))))/LEN([@[Filter List]])**

**Quick Explanation: **

- Calculate length of each ‘Name’ text
**LEN(CA_Cities___Wikipedia[Name])-** - Calculate length of each ‘Name’ text after substituting search word with a blank
**LEN(SUBSTITUTE(LOWER(CA_Cities___Wikipedia[Name]),LOWER([@[Filter List]]),””))** - Step 1 subtract step 2. Take these results and divide by search word length
**/LEN([@[Filter List]])**

**There’s probably a shorter way to solve this in a single cell. Can you think of a way? **

We could of course use a non array formula as a helper column for each unique search word. In many ways this would be a better solution as it would be less complex to understand.

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy playing with my dogs Cali & Fenton, learning Spanish, playing Chess and reading Excel books

]]>We have thousands of these non normalized mini ranges or groups of data stacked on top of each other. It’s always the same number of spaces between the groups.

** We need to sum the numbers for each combination of business unit and year. Here’s the twist! We only sum the numbers from the groups of data that have “total” as the second title word!**

The good news is that the business units are always in the same vertical order and the years are in the same left to right order.

Before we start writing formulas or vba code we really should ask a couple of questions that will determine how we solve this:

**Is this a quick one time task or a long term project?****Does your co-worker or client want/need to understand the solution?**

This is a good method if it’s a long term project that will have additional questions. In this case it’s worth the time to normalize that data and then use simple Pivot Tables or formulas. It would also be easy to add helper formula columns. **Re-arranging or normalizing the data into a database format makes the analysis so much easier!**

If this is a quick one time task then maybe it’s not worth spending the time to re-arrange/normalize the data. We can create a very simple helper column that will repeat the second text word.

Then, in cell E2, we use this formula **=SUMIFS(E$13:E$655,$B$13:$B$655,”total”,$D$13:$D$655,$D2) **drag it over and down** **and we are finished! Time for ice cream!

For the brave at heart we can use a single array formula! No need to re-arrange the data or use a helper column.

This is our array formula–> **=SUM(N(OFFSET(E$8,IFERROR(IF(($F$9:$F$655=”total”),ROW($C$9:$C$655)-ROW($C$9)+$C2,0),0),0)))**

**How does it work? **Let’s look only at the OFFSET part for now.

**OFFSET(E$8,IFERROR(IF(($F$9:$F$655=”total”),ROW($C$9:$C$655)-ROW($C$9)+$C2,0),0),0)**

Remember that the mandatory arguments of an OFFSET function are: **OFFSET(Reference, Rows, Cols)** or is simple language **OFFSET(starting cell, go down or up, go left or right)**

This would normally return a single value. However, we know that in this case we need to return several values (a number from each table that has the word “total”). We need a way to put various numbers in OFFSET’s row argument (‘go down or up’).

So, we take our array condition **IF(($F$9:$F$655=”total”) **and each time we find the word “total” we use this **ROW($C$9:$C$655)-ROW($C$9)+$C2 **to give us all of the positions of the number we want in each table that has the word “total” just above it. **Clear as mud?** It would help if you watched my YouTube video on this and audited the file (see below).

Power Query (aka Get & Transform) is the hottest Excel tool since Pivot Tables!

Both Oz du Soleil and Piotr Majcher created Power Query solutions! Check out there videos!

Watch **Piotr’s video!**

Watch **Oz’s video**!

2014 MODELLOFF champion **Diarmund Early** left the comment below with a brilliant SUMIFS formula.

At first it looks like Diarmuid forget to lock the sum range and part of the criteria 1 range. Then I remembered that I used something similar to this several years ago! **It’s a brilliant solution in the “One Time Task” category.**

**How does it work?** The criteria 2 range that’s looking for “Total” is fully locked. the SUM range is not locked at all (rows nor columns). The formula is entered into cell E2 and then dragged down and to the right. Remember that the business units are always in the same order. The main logic to the formula is that the SUMIFS function is expecting ranges with the same number of items. The ranges are almost always parallel to each other but they don’t have to be! They just have to have the same number of elements. Isn’t Excel amazing!!!

**One Time Task: **I’m going with Diarmuid Early’s SUMIFS solution! One simple non array quickly solves it! My helper/sumifs is a distant 2nd.

**Long Term Project:** Power Query wins! Oz du Soleil and Piotr Majcher convinced me! Using VBA to normalize is a decent 2nd prize.

A special thanks to **Oz du Soleil** (http://datascopic.net/), **Piotr Majcher** (http://www.pmsocho.com/) and **Diarmuid Early** (https://theexcelements.com/) for participating!

Get the Excel file **here** (video 00160) or **here.**

You can watch my YouTube video **here**.

** There are so many amazing things that you can do with this powerful software**. Check out my

Away from Excel I enjoy playing with my dogs Cali & Fenton, learning Spanish and playing Chess.

]]>