如何计算tableau public中值的出现和子集的百分比? [英] How to count occurrence of value and percentage of a subset in tableau public?

查看:20
本文介绍了如何计算tableau public中值的出现和子集的百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组以下格式的数据:

I have a set of data in the following format:

Resp | Q1 | Q2
P1   | 4  | 5
P2   | 1  | 2
P3   | 4  | 3
P4   | 6  | 4

我想显示回答大于 3 的人数和百分比.所以在这种情况下,输出将是:

I'd like to show the count and % of people who gave an answer greater than 3. So in this case, the output would be:

Question | Count  | Percent
Q1       |  3     | 75%
Q2       |  2     | 50%

有什么建议吗?

推荐答案

虽然听起来很简单,但实际上有点复杂.首先,您的数据不是基于行的,因此您必须对其进行透视.

Although it sounds like a fairly easy thing, it is a bit more complicated. Firstly your data is not row based so you will have to pivot it.

  1. 将您的数据加载到 Tableau
  2. 在数据源屏幕中选择列 Q1 和 Q1,右键单击它们并选择Pivot"
  3. 将答案命名为答案"(只是为了清楚起见.您应该得到一个如下所示的表格:

现在你需要创建一个计算字段(我称之为Overthreshold来检查你的条件:

Now you need to create a calculated field (I called it Overthreshold to check for your condition:

if [Answer] > 3 then
[Answer]
End

此时,您可以用参数替换 3,以防您想轻松更改该条件.您已经可以按如下方式滴下药丸以获取计数:

At this point you could substitute the 3 with a parameter in case you want to easily change that condition. You can already drop the pills as follows to get the count:

现在,如果您想要百分比,它会变得有点复杂,因为您必须确定问题的数量和答案的数量 > 3,这是存储在两个不同列中的信息.

Now if you want the percentage it gets a bit more complicated, since you have to determine the count of the questions and the count of the answers > 3 which is information that is stored in two different columns.

  1. 使用此计算创建另一个计算字段 COUNT([Overthreshold])/AVG({fixed [Question]:count([Answer])})
  2. 将创建的药丸放到文本"字段或列抽屉中,然后查看百分比值
  3. 右键单击该字段并选择默认属性/数字格式以将其显示为百分比而不是浮点

解释公式的作用:它将超过阈值的答案计数除以每个问题的答案计数.这是由公式的 fixed 部分完成的,它计算 Question 列中具有相同值的行.AVG 之所以存在,只是因为 Tableau 需要在那里进行聚合.由于问题的每条记录的值都相同,因此您还可以使用 MINMAX.

To explain what the formular does: It takes the count of the answers that are over the threshold and devides it by the count of answers for each question. This is done by the fixed part of the formular which counts the rows that have the same value in the Question column. The AVG is only there because Tableau needs an aggregeation there. Since the value will be the same for every record of the question, you could also use MIN or MAX.

感觉应该有一个更简单的解决方案,但现在我想不出一个.

It feels like there should be an eassier solution but right now I cannot think of one.

这篇关于如何计算tableau public中值的出现和子集的百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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