简体   繁体   English

如何计算datastudio中的一系列值

[英]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 ID Component成分 Component 1组件 1 Component 2组件 2
101 101 wood木头 metal金属 gold金子
102 102 metal金属 copper
103 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 2个
metal金属 3 3个
copper 1 1个
gold金子 2 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 ID Component成分
101 101 wood;metal;gold木材;金属;金
102 102 meta;copper元;铜
103 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!谢谢!

Edit编辑

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.

相关问题 Google Datastudio - 从逗号分隔的字符串中提取值 - Google Datastudio - Extract Values from Comma separated String 使用DataStudio为BigQuery中的自定义查询指定日期范围,其中日期范围影响查询中的运算符 - Use DataStudio to specify the date range for a custom query in BigQuery, where the date range influences operators in the query 用于运行具有动态日期范围的不同值计数的 BigQuery - BigQuery for running count of distinct values with a dynamic date-range 如何将 MySql 数据库从 AWS RDS 连接到 datastudio - How to connect MySql Database from AWS RDS to datastudio Google Datastudio:为日期源的两个不同日期列应用日期范围过滤器 - Google Datastudio: Apply Date Range Filter for Two Different Date Columns of Date Source 标准 SQL - 如何计算数组中值的频率 - Standard SQL - How to count frequency of values in array Heroku Postgresql 与 Google Datastudio - Heroku Postgresql with Google Datastudio 如何在要在 Google DataStudio 中使用的应用程序脚本高级服务中指定数组字段? - How to specify array fields in app script advanced services to be used in Google DataStudio? 如何根据 BigQuery 中另一列的条件显示值的计数 - How to show a count of values based on condition of another column in BigQuery 如何将用户定义的 function 应用于 KQL 中的一系列值 - How to apply a user defined function to a range of values in KQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM