SQL 中 GROUP BY 后的 Tableau 计数值 [英] Tableau count values after a GROUP BY in SQL

查看:26
本文介绍了SQL 中 GROUP BY 后的 Tableau 计数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tableau 来显示一些学校数据.我的数据结构给出了一个包含该国所有 de school 课程的表.问题是我需要计算,例如,有多少所学校有小学和学前班(两者都有).

我的表格的简化版本应如下所示:

在那个表中,如果我想知道示例中需要的数字,结果应该是 1,因为只有一所学校同时存在小学和学前班.

我希望在 Tableau 中有一个多重过滤器来为我提供这些信息.

我在考虑应该进行的 SQL 查询,它需要一个 GROUP BY 语句.咨询的一个例子是这里的小提琴:

然后我做了一个计算字段,只留下与他们拥有的类型数量(根据过滤)与多重过滤器中选择的类型数量(上面显示的两个字段)相匹配的学校 ID:

>

最后,我使用 COUNTD([Condition]) 来显示至少与所选学校类型匹配的学校数量.

希望这对有类似问题的人有所帮助.

PS:如果有人想要带有解决方案的工作簿,我已将其上传到 Tableau 论坛

I'm using Tableau to show some schools data. My data structure gives a table that has all de school classes in the country. The thing is I need to count, for example, how many schools has Primary and Preschool (both).

A simplified version of my table should look like this:

In that table, if I want to know the number needed in the example, the result should be 1, because in only one school exists both Primary and Preschool.

I want to have a multiple filter in Tableau that gives me that information.

I was thinking in the SQL query that should be made and it needs a GROUP BY statement. An example of the consult is here in a fiddle: Database example query

In the SQL query I group by id all the schools that meet either one of the conditions inside de IN(...) and then count how many of them meet both (c=2).

Is there a way to do something like this in Tableau? Either using groups or sets, using advanced filters or programming a RAW SQL calculated fiel?

Thanks! Dubafek

PS: I add a link to my question in Tableu's forum because you can download my testing workbook there: Tableu's forum question

解决方案

I've solved the issue using LODs (specifically INCLUDE and EXCLUDE statements).

I created two calculated fields having the aggregation I needed:

Then I made a calculated field that leaves only the School IDs that matches the number of types they have (according with the filtering) with the number of types selected in the multiple filter (both of the fields shown above):

Finally, I used COUNTD([Condition]) to display the amounts of schools matching with at least the School types selected.

Hope this helps someone with similar issue.

PS: If someone wants the Workbook with the solution I've uploaded it in an answer in the Tableau Forum

这篇关于SQL 中 GROUP BY 后的 Tableau 计数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆