[英]Advanced filter/configurator based on dataset
I would like help with a problem, or rather a challenge in Excel and/or Google Sheets.我想在 Excel 和/或 Google 表格中寻求帮助解决问题,或者更确切地说是挑战。
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.
现在我们要创建一种基于此表的搜索 function。
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, ie size, color and/or country of origin and that based on those criteria, all products that meet these criteria are displayed.
然后,我们需要搜索 function,您可以在其中指定一个或多个偏好,即尺寸、颜色和/或原产国,并根据这些标准显示所有符合这些标准的产品。 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.请参阅下面我们文档的图像以及我们希望它看起来如何。
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?
对你来说可能很简单,对我来说很难哈哈你能再帮我一次吗? –
–
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.您的问题非常笼统,我将根据自己的经验尝试在 Excel 或 Google 表格中提供一些关于如何实现它的指南。 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.用于 Excel 的方法可用于 Google Spreadsheet,因为它基于
FILTER
function,这两个工具都有但具有不同的签名。 For Google Spreadsheet you can also use QUERY
that is very powerful for situation like this.对于 Google Spreadsheet,您还可以使用
QUERY
,它在这种情况下非常强大。
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
).在所有情况下,最好有一张包含输入原始数据的工作表(假设为“
Input
”选项卡),然后在第二张工作表中包含过滤数据的工作数据(假设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.这两种工具都在 UI 或切片中提供过滤器功能。 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.
这是需要考虑的事情,但是使用 Excel/Google 电子表格功能,您可以以更友好的方式显示过滤器参数,因为您可以看到所选的参数,而无需额外单击以查找所选的过滤器值。 The approach here is based on Excel/Google Spreadsheet functions.
这里的方法基于 Excel/Google 电子表格函数。
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.您可以使用数据验证列表,这样您就可以 select 每个过滤条件的可能值的子集,然后使用加法乘法以逻辑方式(
OR
或AND
)连接这些条件。
=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).其中每个条件都基于您要限制的过滤器值,每个条件代表一个
{TRUE,FALSE}
值数组,所有这些值的大小都与dataset
(行数)相同。
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.我使用一些通配符值来表示列的所有值,在我的例子中我使用
ALL
,但你可以用不同的方式设置。 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: <>"*"
.表示如果
B3
等于ALL
,则 select 所有D3:D15
行的条件如下: <>"*"
。 Otherwise select only the rows equals to B3
.否则 select 只有行等于
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
.有时我想考虑给定过滤条件的 OR 条件,例如对于给定的过滤条件,考虑
value1
或value2
并且它在过滤值中表示为以逗号分隔的值列表,例如: value1, value2
。
Here, some Stack Overflow questions I posted with answers about how to deal with that:在这里,我发布了一些 Stack Overflow 问题以及有关如何处理该问题的答案:
The FILTER
function here, allows to add the filter conditions via input arguments, so now we have:这里的
FILTER
function 允许通过输入 arguments 添加过滤条件,所以现在我们有:
=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.注意:请记住,在 Google 电子表格中,我们不需要通过将每个条件相乘来添加条件。 It is added via input argument.
它是通过输入参数添加的。
here you can check some of question I posted related to this topic:在这里您可以查看我发布的与此主题相关的一些问题:
In some cases it is better to use QUERY
function.在某些情况下,最好使用
QUERY
function。
Here, a sample file using QUERY
statement and how to combine multiple conditions inserting IF
in the where
statement.这里是一个使用
QUERY
语句的示例文件,以及如何在where
语句中插入IF
来组合多个条件。
sample query on C1
cell: C1
单元格上的示例查询:
=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)
The raw data is in Jira Issues
tab, the data populated is based on multiple filter conditions.原始数据位于
Jira Issues
选项卡中,填充的数据基于多个过滤条件。 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.我为过滤器值使用了一些名称范围,以便更好地理解公式,例如:
startPeriod
、 endPeriod
等。您可以测试将调用的实际查询,查看query
输入参数的合并字符串的结果QUERY
function。
Similarly you can stablish a where
statement to consider whether the input parameter is empty or not.同样可以建立一个
where
语句来判断输入参数是否为空。 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.在这种情况下,您可以构建这样的逻辑,将
IF
块作为where
语句的一部分插入并连接字符串结果。
=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.上面对列
A
或B
的查询,如果未指定输入参数B2
或B3
,则通过条件返回整个列: "<>'*'"
。 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.以类似的方式,您可以为更多参数添加附加条件,重复查询的第三行并更改列和参数单元格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.