Download my Excel file **here** (demo data from data.world).

Drop down list must contain column headers for columns that have currency datatype. If datatypes change the drop list should also change

Last week I would have said that it’s not possible….but **it is possible!**

I used it as part of a DSUM solution (choose currency column to sum).

I used this sample data from **data.world**. 20 total columns and 399 rows.

CELL function extracts datatype from first row of data (assuming entire column is the same).

CELL function doesn’t seem to work as an array so I referenced each cell one by one.

What do the codes mean?

- a code starting with a “C” (cell G1) means currency
- a code starting with an “F” (cell A1) means number

Official list from Microsoft (**link**).

Initially I used an array in cell C4 to count datatypes starting with “C” but I simplified it to this:

=COUNTIF($A$1:$T$1,C5&”*”)

I used dynamic array function SEQUENCE to create a counter in cell B6:

=SEQUENCE(C4,1,1,1)

It spills down only as far as necessary.

Below, the # in B6# is used to spill formula down alongside the counter. No need to drag formula down manually (it automatically extends).

=INDEX(‘blockbuster-top_ten_movies_per_’!$A$1:$T$1,SMALL(IF(LEFT($A$1:$T$1,1)=C$5,COLUMN(‘blockbuster-top_ten_movies_per_’!$A$1:$T$1),””),B6#))

I used OFFSET inside data validation to create the list. CELL & OFFSET are both volatile functions.

=OFFSET($C$6,0,0,$C$4,1)

To double check the solution I also created a drop down list for column headers that have number format. Columns ‘adjusted’ and ‘worldwide_gross’ are formatted as numbers.

Note: if you change a column’s datatype (value in row 2 of sheet ‘blockbuster-top_ten_movies_per_’) you’ll need to press F9 key to refresh the calculation.

After I downloaded the sample data I manually set each column to a specific datatype (as many of them were initially set to “G” for general).

As I mentioned, you may never need to do this but it was fun knowing that Excel can solve this with a few simple formulas. I used this as part of a solution involving DSUM function (hopefully my next post).

To think about: how can I use TYPE function?

Some are described as being a hopeless romantic. I’m not. I’m more of a hopeless Excel fan. I will never obtain true Excel nerdvana but I’ll pursue it forever

My name is Kevin Lehrbass. I’m a Data Analyst. I live in Markham Ontario Canada.

The post CELL Function Adventure first appeared on My Spreadsheet Lab.]]>

My curiosity got the best of me in 2019. Challenge:

Can I make a pixel face move without VBA? (post)

Can I display a message when the face intersects a cell with a number?

Previously, I used VBA to make the face move.

Download my updated Excel file here and follow along below.

I couldn’t get several questions out of my head:

- how did I use formulas to move the face?
- can I incorporate some dynamic arrays?
- can I make formulas less volatile & more efficient?

(a)Each face item has a starting row/column position.

The blue left eye = row 9 and column 8.

(b)Spin buttons added. Cells below “Up/Down” & “Left/Right” above receive spin button values.

(c)Below, current positions = original positions adjusted by spin button values.

Currently values are identical as “Up/Down” & “Left/Right” both = 0. Click spin buttons to change them.

(d)Conditional Formatting rules added for each face item based on (c).

By the way, I just noticed “Duplicate Row” option. How long has that been there?

In 2019 I just put numbers in cells. Conditional formatting added the purple color.

**Could dynamic arrays create purple obstacles that vary in size?**

Goal: move face to green area without touching purple cells . Can I make purple areas change size?

I experimented with formulas like these to create some variability:

- RANDARRAY(RANDBETWEEN(1,4),RANDBETWEEN(1,4),1,1,TRUE)
- SEQUENCE(2,3,INT(RAND()*10),INT(RAND()*10))
- SEQUENCE(RANDBETWEEN(1,3),4,1,0))
- IFERROR(SEQUENCE(INT(RAND()*4),2,5,0),1)

RANDBETWEEN or RAND inside SEQUENCE produced occasional **#SPILL!** errors.

* WHY?* How could it sometimes work? Answer from Microsoft:

Occasional #SPILL! errors annoyed me so I created a non volatile way to create variability! See area with the purple background starting in cell AQ54. INDEX/MATCH inside sequence uses this area.

If the face intersects a purple cell a message will be displayed (see cell AW78).

Some insist on never using volatile functions. I agree 99% of the time (post).

**Remove Volatile Functions:**

My original formula to test overlap between face and number cells used INDIRECT (* !volatile!*).

=IFERROR(SUM(INDIRECT(ADDRESS(AI126,AJ126)) Face),””)

My modified formula below (cell AK78) does not use any volatile functions.

=IFERROR(SUM(Face INDEX($A$1:$BK$35,AI78,AJ78) ),””)

**Only Calculate If Required!**

=IF(AF78>$AG$76,””,IFERROR(SUM(Face INDEX($A$1:$BK$35,AI78,AJ78) ),””))

IF tests if the formula is needed. It compares counter with AG76 value (count cells with numbers).

**ROW & COLUMN functions**

Various formulas used ROW and COLUMN functions many times. I replaced them with hard coded counters. Downside? I’d have to adjust them if I insert new rows or columns.

Example: cell AG78 formula no longer requires ROW & COLUMN functions:

=IF(AF78>$AG$76,””,SMALL(IF(ISNUMBER($D$4:$BK$35),$A$4:$A$35+($D$1:$BJ$1/100),””),AF78))

**Name Range: Face**

The named range to identify the face’s current location used volatile OFFSET function. I changed it to INDEX. Yes, INDEX can be used for a dynamic range (post) and it isn’t volatile.

=INDEX(grid!$A$1:$BK$35,grid!$AC$67,grid!$AG$67):INDEX(grid!$A$1:$BK$35,grid!$AC$67+grid!$S$67-1,grid!$AG$67+grid!$V$67-1)

Thanks to Robert Gascon for reminding me of this a couple of years ago.

**Conditional Formatting**

Conditional formatting rules are “super-volatile” as per Bill Jelen (post). I’ve made the formulas more efficient but CF rules remain volatile. I considered using custom formats as Bill suggested but that would require a full redesign.

**Change the purple obstacles**

To redesign the playing area add/remove the sequence formulas (purple obstacles).

Some good sources for learning more including:

- Volatile Functions: Talk Dirty to Me (www.sumproduct.com)
- Conditional Formatting is volatile (www.vertex42.com)
- Volatile functions – what’s the big deal? (www.vertex42.com)
- Volatile Excel functions (www.decisionmodels.com)

I think the universe played a trick on me.

Previously, I had formatted the input area with custom format “;;;” so numbers wouldn’t be visible. My thinking was probably that this was the easiest way to hide them. I had completely forgotten about this. Somehow two of my formulas had the same format! So the formula was working but I couldn’t see the result!

I won’t admit how long it took me to figure this out!

I’ve taken courses, read books, and watched videos but I still learn the most by building & playing with Excel. Theory can be helpful but hands on experience is essential. It’s also a fun thing to play with while watching NBA/NHL playoffs, Netflix and Prime.

The post Flirting with Volatility first appeared on My Spreadsheet Lab.]]>

Download Daniel’s Power Query solutions.

It’s the same messy data & requirement found in my last post.

He has two Power Query solutions. #1 requires writing some M code. #2 only uses the UI.

I prefer #1! Why?

- M code is shorter
- easier to read the M in #1
- Great way to learn about List !

Steps Source, Change Type, Replace Value are easy steps.

Step Text_Split is a great practical use of creating a List!

I could read the entire M code but best to digest this single step in the formula bar (listed below).

Text_Split = Table.AddColumn(#”Replaced Value”, “TextSplit”, each Text.Split([Time 1],”,”)),

Add new column “TextSplit” based on previous step. For each comma in column [Time 1] split it into separate pieces. Where does PQ put these separate pieces of split text? Into a List!

In column “TextSplit” click in the white space to the right of any “List” to see the list values.

This step is longer but I understood it after a couple of minutes!

Add column called time_intervals based on step Text_Split. And now the heart of this step:

each List.Transform([TextSplit],each Number.From(Text.AfterDelimiter(_,”-“)) – Number.From(Text.BeforeDelimiter(_,”-“)))

List.Transform: reference a list and do something with it’s items. For each item (eg “9-10”) Text.AfterDelimiter gets the “10”, Text.BeforeDelimiter gets the “9”. Number.From converts both text to a number. 10 – 9 = 1.

Now each list contains numbers.

List.Sum sums numbers in each list.

Total_time_intervals = Table.AddColumn(time_intervals, “Total time_intervals”, each List.Sum([time_intervals])),

The final two steps remove columns and change a data type.

I decided not to review this but I included it (top). Why? Solution #1 demonstrates that venturing away from the UI (user interface) and using a bit of M can simplify/shorten the M code. It’s exciting to learn something new especially during these difficult times. Solution #2 isn’t bad…it’s interesting but a longer approach for those that prefer to stick with the UI. I need to push forward with learning about List in M.

I have so much to learn about list functions but I’ll get there one example at a time. * Thanks to Daniel for sharing his solutions with me.* I’m still learning to think in the Power Query manner. It has taken time but I’m getting there. Sometimes it takes someone like Daniel to nudge me in the right direction.

My name is Kevin Lehrbass. I’m a Data Analyst. I live in Markham Ontario Canada. The last few years seem like a renaissance in Excel with Microsoft adding so many new features: dynamic arrays, datatypes, new functions like XLOOKUP etc. Power Query has been around for several years now but I’m still learning it.

The post Calculate Hours from Messy Text using Power Query first appeared on My Spreadsheet Lab.]]>Download my Excel file with solution.

Data exported to Excel looks like this:

I need to calculate total hours in each cell. Cell A2 = 4 hours, cell A3 = 6 hours, etc.

There were 10 columns and 20000 rows (my sample is smaller). Solution needs to be easy to audit.

Initially it seemed daunting. I could use text-to-columns to split out each start/stop value and then a ton of formulas. Urgency of the request forced me to consider alternative methods. Two questions:

Is “+” symbol only used after 3 hour intervals? Are all other time intervals only 1 hour?

The answer was “yes” to both questions. I saw the pattern and solved it like this:

- Count the “+” symbols in each cell.
- Count the commas.
- Total of 1 hour time intervals
- Total of 3 hour time intervals
- Final total.

Sometimes an extra question saves a lot of unnecessary complexity and time!

Yes my solution is boring. No fancy dynamic arrays, vba, or power query. But if there’s a simple way to solve it shouldn’t we consider it? Especially when creating a solution that other people will use.

If the details were more complex (eg “+” didn’t exist, time increment could be any number) then I’d need a brute force method to subtract start time from end time. **A ton of helper columns? Power Query? Mega formula?**

My name is Kevin Lehrbass. I’m a Data Analyst and Excel enthusiast.

The post Calculate Hours from Messy Text first appeared on My Spreadsheet Lab.]]>

(Download my Excel file here)

Why didn’t I remember that I’d solved this and created a post?

Who knows but there are two important differences I’ll review in this post:

- preferred formula solution
- power query variation

The person I helped preferred a simple solution with a couple of quick manual steps:

- create unique ID list =UNIQUE($A$4:$A$13)
- concatenate Codes =TEXTJOIN(“, “,TRUE,IF($A$4:$A$13=$L4,$B$4:$B$13,””))
- copy/paste formula above as values
- text to columns to split the codes

Q: Why not fully automate it?

A: It’s a quick one time task. Fully automating could take more time.

That’s fair. Now I’ll examine a Power Query solution variation.

In my previous post I found this tip that modifies the M code in the advanced editor using *Text.Combine* function.

This variation uses *Text.Combine* using only the menu (no manual M code changes).

**Menu Only Solution Steps:**

**Step 0**

Load data into Power Query.

**Step 1**

The magic is **Operation ‘All Rows’** in the Group By below.

When I group by ID and use ‘All Rows’ in new column ‘AllCodes’, M creates a table in each row.

**Step 2**

I don’t need the entire table for each ID (row). I just need the values from column Code. The Custom Column allows me to extract these values into a list.

Tip: click to the right of text ‘List’ to see the values in bottom left.

**Step 3**

In the column headers press the double arrows, select ‘Extract Values’.

We end up with this:

**Step 4**

I did a couple of cleanup steps and then split column ‘Code 1’ by delimiter (comma).

Close and Load to a new sheet. Yes it’s fully automated but it does take time to learn this approach.

**Simple or Robust?**

Business users with a 1 time task may prefer a formula solution despite a couple of manual steps.

Data nerds like me prefer to invest time to fully automate and learn something new along the way.

**Pitfall**

I did get confused in Step 2. **What am I supposed to extract and from where?**

Answer was **[AllCodes][Code]** (column Code that’s inside the table in column AllFields).

I always try to review what I’ve learned so I don’t forget for the next time it comes in handy (hence making this post to practice!).

I’m a Data Analyst from Markham Ontario Canada (near Toronto). I need to keep my Excel skills up to date for my job but I also find that playing around in Excel helps pass the time during Covid.

The post aggregating text part 2 first appeared on My Spreadsheet Lab.]]>

Template link (Microsoft Tech Community).

Full List of Elisabetta’s Templates:

- Favorite movie list
- Periodic table
- Planets & Comets
- Stars & Constellations
- U.S. college decision helper
- Relocation helper
- Baby name tracker
- Nutrition tracker
- Recipe analyzer
- Fitness tracker
- Investment tracker

I reviewed and recommend ‘Planets and Comets’ and ‘Favorite Movie List’.

I’m critical of poorly designed spreadsheets but these are great. **Why?**

**design:**effortlessly explore/navigate the content. Smart use of font size, instructions, space.**functionality:**slicer displays smaller amounts of info (easier to read). Images added via a simple formula =IFERROR(F7.image, “No image”). Dynamic arrays reduce amount of required formulas.**discovery:**learn tons of facts about planets. Use movie template to start endless conversations.

Seen below is sheet ‘Solar system by the numbers’ from Planets & Comets.

This kind of functionality was pure fantasy when I started working with Excel 20 years ago.

Caldesi used various Dynamic Arrays in the templates including this one:

=TRANSPOSE(INDEX(SORTBY(tblMovies[#Data],tblMovies[My Rating ★],-1,tblMovies[Title],1),SEQUENCE(10),1))

- remember to correctly spell a movie title
- clarify when there’s a duplicate name
- not all movies are recognized. Empty description fields could create errors in sheet Dashboard
- i have a SurfacePro (small screen) so I modified row/column height in a few places
- these DataTypes may not be allowed on your work computer and may not work on all Excel versions. I have Microsoft 365 office insider edition

I played around with the template and added a few movies to get started. I also added a Watch List.

I’m frequently guessing an actor’s age or saying “he/she was in that other movie!”.

Last night we were re-watching GroundHog Day. I had never noticed that Michael Shannon was in the movie! Also in the movie was Brian Doyle-Murray (Bill Murray’s brother!). Another brother, not in the movie, is Joel Murray (MadMen).

A month ago I noticed that comedian Ron James had a minor line in Strange Brew. I recommend Strange Brew only if you are in a goofy mood.

My name is Kevin Lehrbass. I’ve been a Data Analyst for 20 years now.

I struggled to think of an interesting blog post to start the year until I stumbled across these cool templates. Elisabetta did a great job designing these templates. I wonder what else she’ll create?!

The post Discover Data Types templates first appeared on My Spreadsheet Lab.]]>

Such a difficult year but I did learn/practice a lot of things in Excel.

Download it here (new version of file I used last year. It lists posts with links).

**VBA Posts**

I was watching movie The Big Lebowski while flipping through a book by Bob Umlas.

I really dove into VBA that day! (post link)

Tom Urtis shared how to keep the all time min and max values (without keeping everything).

Also based on Worksheet_Change I created a demo showing a cool vba trick.

I used VBA to add color to certain letter(s) inside a cell.

I did this years ago but lost the code and wanted to recreate this. I also included a formula workaround solution.

Merged cells can be such a pain. Now you can take out your frustration by whacking them with your mouse. It was a great way to practice VBA.

**Awkward Data**

Alan Murray created a video about analyzing an awkward data-set.

Alan and Oz used Power Query to solve this. I used a formula solution.

Should I rearrange the data and then add the formulas or add the formulas without rearranging the data?

This time I used Power Query to rearrange the data into a layout that’s easier to analyze.

**Free Data**

Data from data.world about Wayne Gretzky’s goals, some trivia and finally an analysis about whether or not Alex Ovechkin can surpass Gretzky’s record!

**Excel Challenges**

Thanks to Robert for the challenge idea and to Xlarium and Bill Szysz for their ideas.

This one was from Bill Jelen (aka Mr Excel) !

It was a lot of fun participating in this. I created a formula solution.

**Excel & Power BI**

Basic sequences in Excel and Power BI.

It’s constantly in the news and important so why not write a post?

**Misc**

In late April winter was making a last stand so I decided to calculate wind chill in Excel.

My name is Kevin Lehrbass. I’m a Data Analyst. I’ve used various data software over the past 20 years but Excel has been my favorite.

Microsoft has been adding so many new features the last few years so there’s a lot to learn but that’s good because it’s fun!

The post review of 2020 posts first appeared on My Spreadsheet Lab.]]>

Download it **here!**. NOTE: file contains macros (vba)

They are such a pain and cause so many problems. …they’re also a bit intriguing.

This VBA turns range ‘MergedCellRange’ into a merged cell:

MergedCellRange.Activate

With Selection

.MergeCells = True

End With

* Why create more?* I had to simulate what your work colleagues do to you.

Have you played Whack-A-Mole? That’s the concept I’ve used. Your task is to whack (click) merged cells without clicking cells that aren’t merged. Click the mallet button to add merged cells.

Gain points for whacking merged cells. Lose points for whacking non merged cells.

It becomes a memory game trying to remember where the new merged cells are located.

If you keep clicking the mallet without whacking any cells then my code misbehaves something about merged cells merging with other merged cells maybe?

Yes it’s lame but it gave me the chance to practice vba. It includes set, loop, event code, rnd(), etc.

**Set**

This creates a merged cell with some size variation (full code ‘Create Merged Cells’ further down).

Set MergedCellRange = Range(Cells(randr1, randc1), Cells(randr2, randc2))

**Loop**

A For Next loop to create up to 3 merged cells each time you click the mallet.

For X = 1 To LoopC

**Event Code**

Includes a toggle switch. When named range EventCodeSwitch is set to “yes” the code is turned off.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

‘TOGGLE THIS EVENT CODE OFF/ON

If Range(“EventCodeSwitch”).Value = “yes” Then Exit Sub

‘IF CLICKED CELL OUTSIDE RANGE THEN EXIT

If ActiveCell.Column > 46 Then Exit Sub

If ActiveCell.Row > 42 Then Exit Sub

‘IF CELL IS MERGED THEN…

If ActiveCell.MergeCells Then

‘UNMERGES EACH SELECTED MERGED CELL

With Selection

.MergeCells = False

End With

‘INCREASE SCORE: Merged Cells Clicked

Range(“BA20”).Value = Range(“BA20”).Value + 1

Else

‘INCREASE SCORE: Unmerged Cells Clicked

Range(“BA25”).Value = Range(“BA25”).Value + 1

End If

End Sub

**Create Merged Cells**

And finally the code to create the merged cells.

Sub CREATEMERGEDCELL()

Dim randr1 As Integer, randc1 As Integer, randr2 As Integer, randc2 As Integer, randx As Integer

Dim MergedCellRange As Range, actM As Range, LoopC As Integer

LoopC = 3

Application.ScreenUpdating = False

Range(“BA16”).Value = Range(“BA16”).Value + LoopC

For X = 1 To LoopC

‘Assign random values to the variables

randx1 = Int((5 – 1 + 1) * Rnd + 1)

randx2 = Int((4 – 1 + 1) * Rnd + 1)

randc1 = Int((34 – 1 + 1) * Rnd + 1)

randr1 = Int((37 – 1 + 1) * Rnd + 1)

randc2 = randc1 + randx1

randr2 = randr1 + randx2

‘CREATE MERGED CELL RANGE

Set MergedCellRange = Range(Cells(randr1, randc1), Cells(randr2, randc2))

‘SELECT AND MERGE CELLS

MergedCellRange.Activate

With Selection

.MergeCells = True

End With

MergedCellRange.Interior.Color = RGB(Int(Rnd() * 150), Int(Rnd() * 150), Int(Rnd() * 150))

Next X

Range(“BA25”).Value = Range(“BA25”).Value – LoopC

Range(“BA42”).Activate

Application.ScreenUpdating = True

End Sub

Most Excel fans will spend more time playing with the code as that’s more fun!

I’m a Data Analyst living in Markham Ontario Canada.

Microsoft Excel is still my favorite software despite all the new software out there these days.

There’s always something new to learn or old to practice in Excel.

The post whack-a-merged-cell first appeared on My Spreadsheet Lab.]]>

Here’s the link to Robert’s shortest formula challenge.

I initially struggled to understand it. Maybe that’s part of the challenge! On my 3rd attempt I got it!

**Raw Data**

Three columns of raw data in columns A, B, and C. 119 rows of data.

**Multi-step Solution**

Starting in cell E1 we see 8 different matrices. Various combinations of Products (column A) and Variants (column B). Let’s focus on the top matrix (challenge #1).

- SUMIFS, range F3:J6, sum column C based on product and variant conditions
- Column K has a total for each row
- Cell K7 MAX function displays max value from totals above
- “P4” has max total row of 747000. Cell E7 lookup function = “P4” (max total of items P1 P2 P3 P4)

**The Challenge**

Scroll down to row 70 to see challenge #1.

Cell J70 shows answer “P4” by referencing cell E7 that we just saw. **Here’s the challenge:**

For challenge #1 get answer “P4” using a single formula!

I’m won’t attempt to solve this. My victory is understanding Robert’s solution!

Cell K70 has Robert’s formula solution for challenge #1:

=LOOKUP(2,

1/FREQUENCY(0,1/(1+MMULT(SUMIFS(C$2:C$120,

A$2:A$120,”P”&ROW($1:$4),B$2:B$120,”V”&COLUMN(A:E)),

ROW($1:$5)^0))),

“P”&ROW($1:$4))

LOOKUP function has 3 parts. Part 1 and part 3 are simple. Part 2, lookup_vector, is the beast!

LOOKUP(lookup_value, lookup_vector, [result_vector])

**Sneaky Concept**

lookup_value of 2 will never be found in the lookup_vector. Huh? I’ll explain:

I’ve evaluated (using F9 key) lookup_vector and [result_vector]. Results are:

=LOOKUP(2,

{#DIV/0!;#DIV/0!;#DIV/0!;1;#DIV/0!},

{“P1″;”P2″;”P3″;”P4”})

2 isn’t found in the lookup_vector . 1 is the only number in lookup_vector.

If the only number is equal to or less than the lookup_value the function can return the [result_vector] answer. As the lookup_vector 1 is in the 4th position the [result_vector] gives us “P4”.

Let’s modify it a bit:

=LOOKUP(2,

{1;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!},

{“P1″;”P2″;”P3″;”P4”})

Now the answer is “P1”.

=LOOKUP(2,

{#DIV/0!;2;3;3;4;#DIV/0!},

{“P1″;”P2″;”P3″;”P4”})

Answer is “P2”. Ok…let’s move on.

**The Brain**

**lookup_vector **is the brain of Robert’s solution:

1/FREQUENCY(0,1/(1+MMULT(SUMIFS(C$2:C$120,

A$2:A$120,”P”&ROW($1:$4),B$2:B$120,”V”&COLUMN(A:E)),

ROW($1:$5)^0)))

Inside SUMIFS he has used ROW and COLUMN to create the “P” and “V” values:

Select criteria1 “P”&ROW($1:$4) and press F9 key to see: {“P1″;”P2″;”P3″;”P4”}

Select criteria2 “V”&COLUMN(A:E) and press F9 key to see: {“V1″,”V2″,”V3″,”V4″,”V5”}

SUMIFS looks like this:

SUMIFS(C$2:C$120,

A$2:A$120,{“P1″;”P2″;”P3″;”P4”},B$2:B$120,{“V1″,”V2″,”V3″,”V4″,”V5”})

Let’s audit MMULT function using the F9 key to see the results:

Using F9 on MMULT’s array1 and array2 gives us:

=LOOKUP(2,

1/FREQUENCY(0,1/(1+MMULT({122000,0,128000,123000,175000;128000,0,171000,209000,123000;0,0,0,0,0;196000,0,111000,211000,229000},{1;1;1;1;1}))),

“P”&ROW($1:$4))

Examine the numbers inside MMULT. They are the same numbers found in range F3:J6 !MAGIC!

…the final result of MMULT is:

=LOOKUP(2,

1/FREQUENCY(0,1/(1+{548000;631000;0;747000})),

“P”&ROW($1:$4))

Notice something? {548000;631000;0;747000} are total column numbers from range K3:K6 !MAGIC!

and now evaluate what FREQUENCY function does:

=LOOKUP(2,

1/FREQUENCY(0,1/{548001;631001;1;747001}),

“P”&ROW($1:$4))

…eventually becomes this:

=LOOKUP(2,

1/{0;0;0;1;0},

“P”&ROW($1:$4))

and then:

=LOOKUP(2,

{#DIV/0!;#DIV/0!;#DIV/0!;1;#DIV/0!},

“P”&ROW($1:$4))

As Robert says in his comment below, FREQUENCY function returns the maximum of the row totals.

F9 key is your best friend. Use it until you see how Robert gets the same result but in only 1 formula. I just realized that it’s 10pm and I forgot to eat supper. Who needs food when you have an interesting formula to audit

A special thanks to Robert Gascon for this interesting Excel challenge. We need these kinds of distractions these days.

As amazing as Robert’s formula solution is there’s no way I’m going to attempt to create a shorter solution! Is it possible? Maybe…but I’ll let others try.

Follow Robert’s contributions to Microsoft Tech Community: https://techcommunity.microsoft.com/t5/user/viewprofilepage/user-id/280482

The post Robert Gascon’s Shortest Formula Challenge first appeared on My Spreadsheet Lab.]]>

**Task**

For each ‘Code’ concatenate ‘Batch 1’ numbers. Sort ‘Code’ and sort ‘Batch 1’ values for each ‘Code’.

Sounds easy but what approach should we use:

- fully automated (possibly complex solution) ?
- mostly automated (minor manual step needed but simpler solution) ?

Download my Excel file to see solution details (includes Robert Gascon’s ‘Old but Wise’ solution!).

**Pivot & Formula**

My favorite. If you can live with one manual step (sorting ‘Batch 1’ values) then this is it!

**Power Query**

My other favorite. I had to learn a trick in Power Query (modifying the M code: link).

**Dynamic Array Formula**

It was good practice but it did get complicated combining dynamic array functions.

**Old School Formula**

This just got ugly. I’m sure there’s a non dynamic array formula solution but mine was ugly

**Old But Wise**

Robert Gascon sent me his amazing solution. Notice how he used the INDEX function and also AGGREGATE function. Thanks Robert.

**Ultra Modern**

Daniel Choi sent me various dynamic array solutions and also a power query solution. Thank you Daniel. I will update the file later.

**Which solution do you prefer?**

**Do you have a better solution?**

This is me Kevin Lehrbass. I’m a Data Analyst and live in Markham Ontario Canada.

If you haven’t noticed I really like Microsoft Excel. It keeps evolving with new features so I’ll never learn everything. I guess that’s good. I’ll always have something to do.

The post Aggregating Text first appeared on My Spreadsheet Lab.]]>