Category Archives: filtering

#Excel Super Links #100 (Special Edition) – shared by David Hager


My Top 10 Most Underviewed Posts (IMO)

Please check out these posts on my website. There are some powerful techniques to be found here.

#Excel: Getting the Sunrise and Sunrise Times From an Address by David Hager

#Excel: Removing Outliers with Excel Formulas to Modify Control Limits by David Hager

#Excel: Using Conditional Formatting to Highlight 3D Formulas with Defined Names by David Hager

Getting the Latest Earthquake Alert Using the WEBSERVICE and FILTERXML Functions in #Excel by David Hager

Creating a Unique Delimited String from an Excel Filtered List by Using the TEXTJOIN Function By David Hager

Excel: Conditional Format Rows in List 1 that are Not in List 2 by David Hager

#Excel Short and Sweet Tip #17 (Returning a Letter Grade Based on a Normal Grading Scale Without Lookup Table) by David Hager

The DAX ENDSWITHX Function Equivalent

Returning the First Temperature in PowerPivot

#Excel Short and Sweet Tip #25 (Random Sound – Worksheet UDF) by David Hager



#Excel Super Links #91 – shared by David Hager


Copy a Data Table from PDF into Excel

Filtering PivotTables with VBA? Deselect Slicers First!

Use Multiple Connections Between Power BI Tables

Database Functions in Excel

Conditional Formatting Gem in #Excel: Highlight the N Closest Values to the Mean of a Range in a Filtered List by David Hager

#Excel Super Links #61-90: > 150 Excel and BI Links


I had mentioned previously that I used this wonderful Word technique to combine 30 Word files to make these collections.

One thing I did not mention was that there was a lot of blank space creating during the file consolidation. On the previous 2 ESL collections the space was laboriously removed manually. Not wanting to have to do this again, I searched the net and found this comment in a discussion about removing blank space from Word documents.


“Replacing ^p^p with ^p actually is the proper way to remove empty paragraphs.

However, when my documents contains e.g. ^p^p^p^p or similar, it won’t pick them all up and will again leave ^p^p. So I’ve to run this search/replace operation a few times until all cases have been covered.”


In order to get rid of all of the empty paragraghs, I needed 8 repeat operations of this type. You can download the resulting Word file containing >250 links to great Excel and Power BI content here.

Excel Super Links 61-90

Conditional Formatting Gem in #Excel: Highlight the N Closest Values to the Mean of a Range in a Filtered List by David Hager


I am extending the closest value technique I published recently to calculate the same based on a filtered list.

In this demonstration, the goal is to highlight values in a numeric range that are clostest to the average of that range in a filtered list. So, we first make the range dynamic with the following defined name formula.

NumRange =OFFSET(Sheet1!$A$1,1,,COUNTA(Sheet1!$A:$A)-1)

Then, we modify that range to include only filtered values.

fNumRange =IFERROR(IF(SUBTOTAL(3,OFFSET(NumRange,ROW(NumRange)-MIN(ROW(NumRange)),,1)),NumRange,””),””)

For more information on the SUBTOATL function as used here, see:

Next, we use that range to make an array of the absolute differences of each value of the range from the average.

ABS_Range =IFERROR(ABS(fNumRange-AVERAGE(fNumRange)),””)

We can then define a cell for the number of values to highlight.

N_Values =$B$2

The heavy work is done by the next formula, which creates an array of the N values to be higlighted.



This formula returns the position of each smallest deviation in the 2nd argument of the INDEX function, which then returns the values corresponding to those deviations, based on a filtered list. The use of the formula syntax needed to do this with the INDEX function is explained at the following link.

This formula can now be used in the creation of the CF, where CF Formula is =SUM(N(A1=Num_Array)), starting at A1 and applied to all of Column A.

The result of this CF is shown below.


The example file can be downloaded here.


Advanced Filter Magic by David Hager


Previously, I discussed the use of a custom list with Data Advanced Filter.

In the article, I only showed one custom list being used in the advanced filter. However, in most situations, a number of specific searches are required. To illustrate this, I combined all of the links from ESL #1-60 in an Excel file. The description of the links are in column A and the links are in column B. The goal is to perform multiple searches with lists while using only a single formula in the advanced filter. A picture of this can be seen in the following figure.


The formula in the advanced filter (B1:B2) on the AdvFilterTable tab is


where Choice=CHOOSE(MATCH(AdvFilterTable!$A$2,CritLists,0),PowerBIList,VBAList,ExcelList)

This is the key formula for returning the desired list into the advanced filter formula.It is controlled by cell A2, which uses Data Validation with the following list.


The criteria lists tied to the CHOOSE function are are shown in the following figure.


These are expanding dynamic lists to add additional criteria if necessary.


VBAList =OFFSET(LList!$B$1,1,,COUNTA(LList!$B:$B)-1)

ExcelList =OFFSET(LList!$C$1,1,,COUNTA(LList!$C:$C)-1)

When a list is selected in cell A2 and the advanced filter is applied to the links table, the result is as shown below.


Functionally, you can search all of my links for the content you desire. Also, you can use this filter model with your own data and criteria. I hope that this is useful.

You can download the file here.



Using the CHOOSE and AGGREGATE Functions To Apply Conditional Formatting to a Filtered List in Excel By David Hager

The very 1st article I wrote for my blog was about highlighting values in a filtered list. I decided that it was time to revisit that subject. Specifically, I had written an article for Rob Collie about using the CHOOSE function with conditional formatting (CF) in Excel. It turned out that the article was too complex to be useful.

So, I decided to incorporate the use of the CHOOSE function into my original article and give it a friendly user interface. The two user inputs were both created using Data Validation with the List option. They are defined as shown below and pictured in the following figure (showing unfiltered list).




These inputs are used to return values needed by the CF conditions. TopN is selected by the user in cell B1. Cell B2 gives a choice of Large or Small. The following formula converts this information into a number to be used by the CHOOSE function.


The CF conditions are made to be applied to column B. When each formula is defined, the active cell needs to be B6.





When combined with the CHOOSE function (the formula used for the CF), they provide a methodology to highlight filtered rows, as shown below (filter set to display values of 50 to 175 in column B).


If a way to visualize TopN and BottomN simultaneously was required, a second CF condition can be appled to column B.

=CHOOSE(CritNumber, SmallCondition, LargeCondition)

The following figure shows the result.


This is just a demonstration of the versatility of using CF condtions in filtered lists. The application of this method to many columns can be done, as well as the use of different CF conditions. I might write another article about this subject later, but for now, enjoy! Click the link below to download the working file.


Creating a Unique Delimited String from an Excel Filtered List by Using the TEXTJOIN Function By David Hager

Some time ago (16 years – which is 100 in Excel years) I developed a formula solution for counting the number of unique items in a filtered list. I realized that this methodology could be used with the new TEXTJOIN function in Excel (Office 365 version). See the original publication in EEE# 20:

The following defined names are needed to construct the formula.



unRge returns an array that contains only filtered items.


In the figure, rows 2,3,4,6,8,10,11,12,15,17,18,19,and 20 are visible. To return a unique delimited string for only those visible rows, use the following formula (in E3):


which affords


You can download the file here.


Remember again, that you have to have the Excel version included in Office 365 in order for the TEXTJOIN formula to work.