google-sheetsfilteradvanced-filter

Advanced filter/configurator based on dataset


I would like help with a problem, or rather a challenge in Excel and/or Google Sheets.

What we want to develop is as follows:

We have a table of products and certain attributes. Now we want to create a kind of search function based on this table.

Let me give a simple example. Suppose you have as a product an apple, a banana and an orange. The characteristics associated with these are size, color country of origin. We then want a search function, where you indicate one or more preferences, i.e. size, color and/or country of origin and that based on those criteria, all products that meet these criteria are displayed. So if you specify oblong as the size and do not specify any other criteria, it only shows "Banana. If the banana and the orange have Holland as their country of origin and you only give Holland as the criteria country of origin, it will show 'Banana' and 'Orange'. If you say country of origin Netherlands and format oblong, it again shows only 'Banana'

See below an image of our document and how we would like this to look approximately.

enter image description here

Currently, there is no existing formula, because we simply do not know if this can be done and how best to do it.

The document can be accessed at:

A copy of our document with sample data: Document

ADDITION: Hi, Unfortunately I still am not able to get it to work. I am not really a hero in coding/functions. I created a bit more of a clear view in my file and also set the language of my sample file to english. You can find it here: Sample

What I actually need is just that it shows the data on 'Datasheet' if conditions on the left (parameters/value) are met, but only if they are filled. Probably easy one for you, hard to me haha Could you help me out once more? –


Solution

  • Your question is very generic, I will try provide here some guidelines on how to achieve it in Excel or Google Sheet based on my own experience. The approach used for Excel can be used for Google Spreadsheet, since it is based on FILTER function that both tools have but with different signature. For Google Spreadsheet you can also use QUERY that is very powerful for situation like this.

    In all cases, it is a good practice to have a sheet with the input raw data (let's say Input tab), then in second sheet the working data of filtered data (let's say WorkData). This is specially relevant when the raw data is big dataset, so you don't touch the original data set, and instead you have the filtered data in a separated tab.

    Both tools offer filter features in the UI or slice. This is something to consider, but using Excel/Google Spreadsheet functions, you can show the filter parameters in a more friendly manner, because you can see the parameters selected without additional click to find what filter values where selected. The approach here is based on Excel/Google Spreadsheet functions.

    Excel

    Let's say you have a block of filter conditions that you want to apply to a range of data. You can use data validation list so you can select a subset of possible values for each of the filter conditions and then to concatenate such conditions logically (OR or AND) using multiplication of addition.

    =FILTER(dataset, condition1 * condition2...conditionN)
    

    where each condition is based on the filter value you want to restrict and each condition represents an array of {TRUE,FALSE} values all of them of the same size as dataset (number of rows).

    I use some wildcard values to represent all values of the column, in my case I use ALL, but you can setup in a different way. In such case the filter doesn't take effect, but we want to make it work when a specific value is selected. The following trick can be used for both scenarios.

    IF(B3="ALL", D3:D15<>"*",D3:D15=B3)
    

    indicating that if B3 is equal to ALL, then the condition to select all of the D3:D15 rows is the following: <>"*". Otherwise select only the rows equals to B3.

    Sometimes I would like to consider OR conditions for a given filter condition, for example for a given filter condition, consider value1 or value2 and it is represented in the filter value as a list of values delimited by comma, for example: value1, value2.

    Here, some Stack Overflow questions I posted with answers about how to deal with that:

    1. Filter an excel range based on multiple dynamic filter conditions
    2. Filter an excel range based on multiple dynamic filter conditions (with column values delimited)

    Google Spreadsheet

    The FILTER function here, allows to add the filter conditions via input arguments, so now we have:

    =FILTER(dataset, condition1, condition2...,conditionN)
    

    Note: Keep in mind in Google Spreadsheet we don't need to add the conditions by multiplying each one of them. It is added via input argument.

    here you can check some of question I posted related to this topic:

    1. Using ARRAYFORMULA with SUMIF for multiple conditions combined with a wildcard to select all values for a given condition
    2. Using ARRAYFORMULA with SUMIF for multiple conditions combined with conditions using a wildcard. Result by Months

    In some cases it is better to use QUERY function.

    Here, a sample file using QUERY statement and how to combine multiple conditions inserting IF in the where statement.

    sample query on C1 cell:

    =query('Jira Issues'!$A:$T, "where " 
     & IF(B2="", "G is not Null", "G >= date '"
     & TEXT(startPeriod,"yyyy-mm-dd")&"'") 
     & IF(B3="", "", " and G <= date '"
     & TEXT(endPeriod,"yyyy-mm-dd")&"'") 
     & IF(OR(B4="ALL",B4=""), "", " and A='"&B4&"'") 
     & IF(OR(B5="ALL",B5=""), "", " and I='"&B5&"'") 
     & " label A 'Team', S 'Reporter', T 'Assignee', 
         P 'Env.', I 'Release'",1)
    

    sample using Query

    The raw data is in Jira Issues tab, the data populated is based on multiple filter conditions. I am using some name ranges for the filter values for a better understanding of the formula, such as: startPeriod, endPeriod, etc. You can test the actual query will be invoked looking at the result of the consolidated string of the query input argument of QUERY function.

    Similarly you can stablish a where statement to consider whether the input parameter is empty or not. In such case, you can build a logic like this inserting an IF block as part of the where statement and concatenate the string result.

    =QUERY(Input!A:Y, 
      "select *" & " where A " & IF(B2="", "<>'*'", "='"&B2&"'")
      "and " & " where B " & IF(B3="", "<>'*'", "='"&B3&"'")  
    ,1)
    

    The above query for column A or B, returns the entire column via condition: "<>'*'" if the input parameter B2 or B3 were not specified. In a similar way you can add additional conditions for more parameters, repeating the third line of the query and changing the column and the parameter cell.

    Recommendations

    1. Focus on a specific tool: Excel or Google Spreadsheet, even they have some similarities, you need to get familiar with the specifics of each one of them.
    2. Try to start working on your specific problem, once you face impediments, do some research, usually you are not the first person facing this problem, if you don't find a solution, then post your specific problem using a sample as an extract of your real problem (in English, your sample is in other language). Generic questions like this one are difficult to get some attention.