Dynamic Filter Syntax Assistance

shellp

Board Regular
Joined
Jul 7, 2010
Messages
217
Office Version
  1. 365
  2. 2021
  3. 2010
  4. 2007
Platform
  1. Windows
Hello,

I want to create filter formulae dynamically based on values in cells in the worksheet. The formula below works to filter [Fiscal Year] to the value in C4:
Excel Formula:
Filter(raw_All, Indirect("raw_All[Fiscal Year]")=""&C4)

But what if I want the equal sign (=) to also be dynamic i.e. in B4 where the = or <> would be present in the above formula - what is the syntax? What if I want [Fiscal Year] to be dynamic based on a column name in C5 and how does that impact the formula above?

Any and all assistance greatly appreciated.
 
If raw_All is a table, and Fiscal Year is a column in that table, you don't need INDIRECT.

If the table and C4 both contain numeric values you do not need to, and should not, append the null string for your comparison.

You cannot make an operator dynamic. However, you can do something like this. In B4 put something like EQUAL or NOT EQUAL then your formula can be

Excel Formula:
=FILTER(raw_All, (OR(AND(B4="EQUAL",raw_All[Fiscal Year]=C4),AND(B4="NOT EQUAL",raw_All[Fiscal Year]<>C4))))

If you want the column reference to be dynamic then you will need INDIRECT.
Excel Formula:
=FILTER(raw_All, (OR(AND(B4="EQUAL",INDIRECT("raw_All["&C5&"]")=C4),AND(B4="NOT EQUAL",INDIRECT("raw_All["&C5&"]")<>C4))))

However, I'm not sure what you're trying to do. This last formula still assumes you have a column of years. If you want to check for a match on year on Fiscal Year but return the data from a different column, you need a different formula. But the formula above gives you exactly what you asked for.
 
Upvote 0
Hello,

Thank you so much for your response. I went with the following that works:

Excel Formula:
=FILTER(raw_All,(IF(C4="All",raw_All[Fiscal Year]<>"",raw_All[Fiscal Year]=C4))*(IF(C6="All",raw_All[Month]<>"",TEXT(raw_All[Month],"MMMM")=C6))*(IF(C8="All",raw_All[DOW]<>"",raw_All[DOW]=C8))*(IF(E4="TOH",raw_All[campus]<>"",raw_All[campus]=E4))*(IF(E6="All",raw_All[Gender]<>"",raw_All[Gender]=E6))*(IF(E8="All",raw_All[AgeGroup]<>"",raw_All[AgeGroup]=E8))*(IF(H4="All",raw_All[Marital_Status_Desc]<>"",raw_All[Marital_Status_Desc]=H4))*(IF(H6="All",raw_All[AdmFromDesc]<>"",raw_All[AdmFromDesc]=H6))*(IF(H8="All",raw_All[Disposition]<>"",raw_All[Disposition]=H8))*(raw_All[Fall_Visit]>0))

Note that the data is one line per data so how do I use this filter in a formula to summarize specific columns and summing raw_all[total_visits]? How to use a filter like this in a let statement to get various other fields? Thanks.
 
Upvote 0
Your question just got a lot bigger. Someone else may be able to help but I am not able to solve this without being able to see the file.
 
Upvote 0
Thanks Jeff. Should I post as a separate question?
 
Upvote 0
I'm not sure what the convention is for that here, and I'm not a moderator. Anybody can still contribute to this thread.

The essential thing is, I think, that we need to see your table.
 
Upvote 0
Hello Again,

Below is a picture of the worksheet the user will be able to select "all" or a specific drop down from the dataset.

1742062329008.png

The formula below accurately filters raw_all based on the filter selections above.
Excel Formula:
=FILTER(raw_All,(IF(C4="All",raw_All[Fiscal Year]<>"",raw_All[Fiscal Year]=C4))*(IF(C6="All",raw_All[Month]<>"",TEXT(raw_All[Month],"MMMM")=C6))*(IF(C8="All",raw_All[DOW]<>"",raw_All[DOW]=C8))*(IF(E4="TOH",raw_All[campus]<>"",raw_All[campus]=E4))*(IF(E6="All",raw_All[Gender]<>"",raw_All[Gender]=E6))*(IF(E8="All",raw_All[AgeGroup]<>"",raw_All[AgeGroup]=E8))*(IF(H4="All",raw_All[Marital_Status_Desc]<>"",raw_All[Marital_Status_Desc]=H4))*(IF(H6="All",raw_All[AdmFromDesc]<>"",raw_All[AdmFromDesc]=H6))*(IF(H8="All",raw_All[Disposition]<>"",raw_All[Disposition]=H8))*(raw_All[Fall_Visit]>0))

The Columns fields are also drop down and the number is the column ID so I can dynamically choose ChooseCols() (or whatever other syntax is required) for these fields. In other words, the filter fields don't necessarily become grouping fields. The "raw_all" table is one row per encounter and I want to sum the "count" field per the 3 columns above that are selected based on the filter formula selected. Note the "etc" is just so I am not indicating all 7 days of the week for demonstration purposes but would want each as applicable in the actual table.

1742062883083.png


I am assuming this can be done in a spill array but I just am not sure how to go about it. Any assistance greatly appreciated, thanks.

Shelley
 
Upvote 0
Sorry, I thought you just wanted the resulting table.

raw_all.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1Fiscal YearMonthGenderDOWAgeGroupMarital_Status_DescAdmFromDescDispositionFallDxDescMainDxFall_VisitCountcampusMRNEncounterAmCareTypeRegDateFallDxDOW_NumAgeAgeGrpMarital_StatusInstFromInstFromTypeInstFromDesc
22013AprFMonday75 to 84UNKNOWNInpatient complex continuing careDischarged Home (private dwelling, not an institution) With NO Support ServicesFall on same level from slipping, tripping and stumblingInjury of nerves and spinal cord at neck level11Sunshine General1111112013000000ED2013-04-01W012753U526293Almonte General Hospital
32013AprMMonday75 to 84MARRIEDNo Institution - Admit from HomeDischarged Home (private dwelling, not an institution) With NO Support ServicesPneumonia, organism unspecified01Sunshine General2222222013111111ED2013-04-012783M
42013AprMMonday65 to 74UNKNOWNNo Institution - Admit from HomeDischarged Home (private dwelling, not an institution) With NO Support ServicesOther functional intestinal disorders01Sunshine General3333332013222222ED2013-04-012743U
52013AprMMonday65 to 74SINGLEAmbulatory care clinicAdmitted directly to ICU/SCU or OR room (in own facility)Intracranial injury01Sunshine General4444442013333333ED2013-04-012692S54071NPembroke Regional Hospital (AM)
62013AprFMonday85 and olderWIDOWEDNo Institution - Admit from HomeDischarged Home (private dwelling, not an institution) With NO Support ServicesPain in throat and chest01Sunshine General5555552013444444ED2013-04-012913W
72013AprFMonday65 to 74WIDOWEDNo Institution - Admit from HomeDischarged Home (private dwelling, not an institution) With NO Support ServicesMalignant neoplasm of bronchus and lung01Sunshine General6666662013555555ED2013-04-012682W
Sheet1
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Spill Array Syntax
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top