Filter with dynamic output

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
209
Office Version
  1. 365
Platform
  1. Windows
I would like to extend the formula I currently have so that the user is able to select the information required, eg instead of being just Name and Age as in the output range, it could be Name and Dept or Name and Salary or Name, Age and Dept. The only constant required in the output range is the Name field. I have included a Data Validation cell to gather that information but it only allows for one cell entry so perhaps getting Name, Age and Dept may be asking too much, if that is the case I'm happy for it to be restricted to just 2 bits of information eg Name and Salary or Name and Age etc.
It would also be desirable if it doesn't cause too much complication that the field headings are automatically produced so that if Name and Age are selected then the output range contains the field headings Name and Age.
Book1
ABCDEFGHI
1DeptHR
2NameSalaryAgeDeptInfo requiredDept
3Tom45065HROutput
4Jane70080SalesName
5Pete95050AdminTom65
6Harry120040HRHarry40
7Fred145025Admin
Sheet1
Cell Formulas
RangeFormula
H5:I6H5=FILTER(CHOOSE({1,2},$A$2:$A$7,$C$2:$C$7),$D$2:$D$7=$G$1)
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
G1List=$D$3:$D$7
G2List=$B$2:$D$2
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I think I tested various options:

Book1
ABCDEFGH
2NameSalaryAgeDeptSalary Range
3Tom45065HRAge Range4060
4Jane70080SalesDeptHR
5Pete95050Admin
6Harry120040HRHarry
7Fred145025Admin
Sheet1
Cell Formulas
RangeFormula
F6F6=IFERROR(FILTER(A3:A7,IF(""=G2,1,(B3:B7>=G2)*(B3:B7<=H2))*IF(""=G3,1,(C3:C7>=G3)*(C3:C7<=H3))*IF(""=G4,1,D3:D7=G4)),"")


Book1
FGH
2Salary Range
3Age Range
4DeptAdmin
5
6Pete
7Fred
Sheet1
Cell Formulas
RangeFormula
F6:F7F6=IFERROR(FILTER(A3:A7,IF(""=G2,1,(B3:B7>=G2)*(B3:B7<=H2))*IF(""=G3,1,(C3:C7>=G3)*(C3:C7<=H3))*IF(""=G4,1,D3:D7=G4)),"")
Dynamic array formulas.


Book1
FGH
2Salary Range10002000
3Age Range
4DeptAdmin
5
6Fred
Sheet1
Cell Formulas
RangeFormula
F6F6=IFERROR(FILTER(A3:A7,IF(""=G2,1,(B3:B7>=G2)*(B3:B7<=H2))*IF(""=G3,1,(C3:C7>=G3)*(C3:C7<=H3))*IF(""=G4,1,D3:D7=G4)),"")
 
Upvote 0
Hi Kweaver, thanks for that suggestion, I'm only getting one field with it though and that is the name field.
 
Upvote 0
How about using data validation for the output headers like
Fluff.xlsm
ABCDEFGHIJK
1DeptHR
2NameSalaryAgeDeptInfo requiredDept
3Tom45065HROutput
4Jane70080SalesNameDeptSalaryAge
5Pete95050AdminTomHR45065
6Harry120040HRHarryHR120040
7Fred145025Admin
Source
Cell Formulas
RangeFormula
H5:K6H5=CHOOSECOLS(FILTER(A3:D100,D3:D100=G1),MATCH(TOCOL(H4:K4,1),A2:D2,0))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
H4:K4List=$A$2:$D$2


Fluff.xlsm
ABCDEFGHIJK
1DeptHR
2NameSalaryAgeDeptInfo requiredDept
3Tom45065HROutput
4Jane70080SalesAgeName
5Pete95050Admin65Tom
6Harry120040HR40Harry
7Fred145025Admin
Source
Cell Formulas
RangeFormula
H5:I6H5=CHOOSECOLS(FILTER(A3:D100,D3:D100=G1),MATCH(TOCOL(H4:K4,1),A2:D2,0))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
H4:K4List=$A$2:$D$2
 
Last edited:
Upvote 0
Solution
Hi Kweaver, thanks for that suggestion, I'm only getting one field with it though and that is the name field.
Change the output range: =IFERROR(FILTER(A3:D7,IF(""=G2,1,(B3:B7>=G2)*(B3:B7<=H2))*IF(""=G3,1,(C3:C7>=G3)*(C3:C7<=H3))*IF(""=G4,1,D3:D7=G4)),"")
 
Upvote 0
Change the output range: =IFERROR(FILTER(A3:D7,IF(""=G2,1,(B3:B7>=G2)*(B3:B7<=H2))*IF(""=G3,1,(C3:C7>=G3)*(C3:C7<=H3))*IF(""=G4,1,D3:D7=G4)),"")
Thanks Kweaver I'm still not quite getting the desired result where the output is limited to the required fields but I appreciate your effort. It's a nice simple formula which I'll keep working on and see if I can get the desired result.
 
Upvote 0
How about using data validation for the output headers like
Fluff.xlsm
ABCDEFGHIJK
1DeptHR
2NameSalaryAgeDeptInfo requiredDept
3Tom45065HROutput
4Jane70080SalesNameDeptSalaryAge
5Pete95050AdminTomHR45065
6Harry120040HRHarryHR120040
7Fred145025Admin
Source
Cell Formulas
RangeFormula
H5:K6H5=CHOOSECOLS(FILTER(A3:D100,D3:D100=G1),MATCH(TOCOL(H4:K4,1),A2:D2,0))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
H4:K4List=$A$2:$D$2


Fluff.xlsm
ABCDEFGHIJK
1DeptHR
2NameSalaryAgeDeptInfo requiredDept
3Tom45065HROutput
4Jane70080SalesAgeName
5Pete95050Admin65Tom
6Harry120040HR40Harry
7Fred145025Admin
Source
Cell Formulas
RangeFormula
H5:I6H5=CHOOSECOLS(FILTER(A3:D100,D3:D100=G1),MATCH(TOCOL(H4:K4,1),A2:D2,0))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
H4:K4List=$A$2:$D$2
Thanks Fluff, that works well.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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