Best way to query against multiple optional criteria.

berian

New Member
Joined
Jul 8, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I want to create a table where a user can enter data for a 'Stock Alert Message'. The data entered will consist of a Stock Code, Group, Type and Category. I would then like to run a query against this table which will only show us Stock Items which have an alert.

I'm struggling with how to populate the the Stock Alert correctly as we would like some data to be omitted from the user table.

If a Stock Code get's entered then a user wouldn't need to enter any further information as that stock alert would only show against that stock code. However a combination of Group, Type and Category can be entered. If a query matches against more than one criteria then all applicable messages would be shown.

Here's an example of what I mean below.

Stock Alert Messages.xlsx
ABCDEFGHIJ
1
2Stock Alert Messages
3Stock CodeGroupTypeCategoryStock Alert
41/2BI12Test 1
5PLUTest 2
6RLICZSTest 3
7PLU1/2COMTest 4
8
9Query 1Query 2Query 3Query 4
10Stock Code1/2BI12Stock Code10MPF18Stock CodeCAPANTSQUSW1Stock Code1/2CO12
11GroupPLUGroupPLUGroupRLIGroupPLU
12Type1/2Type10MTypeCZSType1/2
13CategoryBIBCategoryPFICategoryCategoryCOM
14Stock AlertTest 1, Test 2Stock AlertTest 2Stock AlertTest 3Stock AlertTest 2, Test 4
15
Sheet1


I've tried looking at various ways of achieving this including FILTER, TEXTJOIN and XLOOKUP but really having trouble putting it together so it works as required. Feel like I've been going round in circles and any help would be really gratefully accepted! If I can provide anymore clarification just let me know!

Many thanks,
B
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Think I'm getting there with this!

Not sure if I've approached this in the most efficient way, but I've managed to figure out a way to get the data I needed!

If anyone has any pointers to what I could do to improve on this - that would be a big help!


Stock Alert Messages.xlsx
ABCDEFGHIJ
1
2Stock Alert Messages
3StockcodeGroupTypeCategoryStock Alert CodeStock Alert
41/2BI12STest 1
5PLUGTest 2
6RLICZSGTTest 3
7PLU1/2COMGTCTest 4
8
9Query 1Query 2Query 3Query 4
10Stockcode1/2BI12Stockcode10MPF18StockcodeCAPANTSQUSW1Stockcode1/2CO12
11GroupPLUGroupPLUGroupRLIGroupPLU
12Type1/2Type10MTypeCZSType1/2
13CategoryBIBCategoryPFICategoryCategoryCOM
14Stock Alert (Expected)Test 1, Test 2Stock AlertTest 2Stock AlertTest 3Stock AlertTest 2, Test 4
15
Sheet1
Cell Formulas
RangeFormula
F4:F7F4= IF([@Stockcode]<>"","S","") & IF([@Group]<>"","G","") & IF([@Type]<>"","T","") & IF([@Category]<>"","C","")
C14,I14,G14,E14C14=TEXTJOIN(", ",TRUE, IF(XLOOKUP(C10,saStcode,alertID,"")="S",XLOOKUP(C10,saStcode,alertMsg,""),""), IF(XLOOKUP(C11,saPgroup,alertID)="G",XLOOKUP(C11,saPgroup,alertMsg,""),""), IF(XLOOKUP(C11&C12,saPgroup&saPType,alertID,"")="GT",XLOOKUP(C11&C12,saPgroup&saPType,alertMsg,""),""), IF(XLOOKUP(C11&C12&C13,saPgroup&saPType&saCategory,alertID,"")="GTC",XLOOKUP(C11&C12&C13,saPgroup&saPType&saCategory,alertMsg,""),""), IF(XLOOKUP(C11&C13,saPgroup&saCategory,alertID,"")="GC",XLOOKUP(C11&C13,saPgroup&saCategory,alertMsg,""),""), IF(XLOOKUP(C12,saPType,alertID,"")="T",XLOOKUP(C12,saPType,alertMsg,""),""), IF(XLOOKUP(C12&C13,saPType&saCategory,alertID,"")="TC",XLOOKUP(C12&C13,saPType&saCategory,alertMsg,""),""), IF(XLOOKUP(C13,saCategory,alertID,"")="C",XLOOKUP(C13,saCategory,alertMsg,""),"") )
Named Ranges
NameRefers ToCells
alertID=data[Stock Alert Code]I14, G14, E14, C14
alertMsg=Sheet1!$G$4:$G$7I14, G14, E14, C14
saCategory=Sheet1!$E$4:$E$7F4, I14, G14, E14, C14
saPgroup=Sheet1!$C$4:$C$7F4, I14, G14, E14, C14
saPType=Sheet1!$D$4:$D$7F4, I14, G14, E14, C14
saStcode=Sheet1!$B$4:$B$7F4, I14, G14, E14, C14
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,097
Members
449,096
Latest member
provoking

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