[英]How to count a range of values in datastudio
I am trying to transform a report that I have made in sheets into the newest datastudio tool.我正在尝试将我在工作表中制作的报告转换为最新的 datastudio 工具。 In my sheet, I have a table where there are several columns that holds data related (this is because each row could have more than one value so I used the "split text into columns" function to represent).
在我的工作表中,我有一个表格,其中有几列保存相关数据(这是因为每一行可能有多个值,所以我使用“将文本拆分为列”function 来表示)。
What I have is something similar to:我所拥有的是类似于:
ID ![]() |
Component![]() |
Component 1![]() |
Component 2![]() |
---|---|---|---|
101 ![]() |
wood![]() |
metal![]() |
gold![]() |
102 ![]() |
metal![]() |
copper![]() |
|
103 ![]() |
wood![]() |
gold![]() |
metal![]() |
In my excel, I have a formula to count the time a certain component is shown by using =COUNTIF(<range>,<string>)
在我的 excel 中,我有一个公式来计算某个组件显示的时间,方法是使用
=COUNTIF(<range>,<string>)
Therefore, with the above formula, I have something similar to:因此,使用上面的公式,我有类似的东西:
Component![]() |
count![]() |
---|---|
wood![]() |
2 ![]() |
metal![]() |
3 ![]() |
copper![]() |
1 ![]() |
gold![]() |
2 ![]() |
I want to be able to build the same in datastudio.我希望能够在 datastudio 中构建相同的东西。 Turns out that since the components are divided into columns, I can only use one dimension and the result only shows the count of the first column.
原来,由于组件被分成列,我只能使用一个维度,结果只显示第一列的计数。
I want to know if there is an easy way to accomplish this.我想知道是否有一种简单的方法可以做到这一点。 My original data source is like this:
我的原始数据源是这样的:
ID ![]() |
Component![]() |
---|---|
101 ![]() |
wood;metal;gold![]() |
102 ![]() |
meta;copper![]() |
103 ![]() |
wood;gold;metal![]() |
Maybe it's easier to work directly with the previous format but again, using the component in this case only counts for the first occurrence and not across the whole string.也许直接使用以前的格式更容易,但同样,在这种情况下使用组件只计算第一次出现而不计算整个字符串。
For now, the only solution I can think of is splitting the text into rows instead of columns, but that is not feasible achievable using Google Sheets, or at least not that I am aware of.目前,我能想到的唯一解决方案是将文本拆分为行而不是列,但使用 Google 表格无法实现,或者至少我不知道。
Could somebody have an idea of how to accomplish this?有人可以知道如何做到这一点吗?
Thanks!谢谢!
I am adding here the minimal reproducible example.我在这里添加最小的可重现示例。 This is the spreadsheet that I have (example) and the current report I am using so far (built-in sheets): Now, I want to have the same report (plus more things) using datastudio.
这是我拥有的电子表格(示例)和目前我正在使用的当前报告(内置表格): 现在,我想使用 datastudio 获得相同的报告(加上更多内容)。 This is the report example I have in data studio.
这是我在数据工作室中的报告示例。 As you will see the
record count
for components is not accurate in DataStudio.正如您将看到的,组件的
record count
在 DataStudio 中并不准确。
Here is a preliminary answer.这是一个初步的答案。 I'll polish if we like it and delete it otherwise.
如果我们喜欢它,我将对其进行润色,否则将其删除。
Consider the following sheet:考虑下表:
Range A2:B4 contains my data of interest.范围 A2:B4 包含我感兴趣的数据。 Rows 7:10 show the results I think you are looking for.
第 7:10 行显示了我认为您正在寻找的结果。 The mechanism for creating this is the value of cell A6 which contains:
创建它的机制是单元格 A6 的值,其中包含:
=ARRAYFORMULA(QUERY(FLATTEN(SPLIT(B2:B4,";")), "SELECT Col1, COUNT(Col1) WHERE Col1 is not null GROUP BY Col1"))
At the highest level, the formula splits each of the delimited text items into their own cell and then flattens all these cells into one column against which we then run a SQL query against the sheet to group and count them.在最高级别,该公式将每个带分隔符的文本项拆分到它们自己的单元格中,然后将所有这些单元格展平到一列中,然后我们针对该列运行 SQL 查询以对工作表进行分组和计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.