简体   繁体   English

Tableau:如果在 for 循环中,如何进行计数?

[英]Tableau: how to make a count if in a for loop?

I'm just starting off Tableau and would like to do a count if in a for loop.我刚刚开始使用 Tableau,并且想在 for 循环中进行计数。

I have the following variables:我有以下变量:

  • City城市
  • User用户
  • Round: takes values of either A or B Round:取 A 或 B 的值
  • Amount数量

I would like to have a countif function that shows how many users received any positive amount in both round A and round B in a given city.我想要一个计数 function 显示在给定城市的 A 轮和 B 轮中有多少用户收到了任何正数。

In my dashboard, each row represents a city, and I would like to have a column that shows the total number of users in each city that received amounts in both rounds.在我的仪表板中,每一行代表一个城市,我希望有一列显示每个城市在两轮中收到金额的用户总数。

Thanks!谢谢!

You can go for a simple solution that works.您可以使用 go 获得一个简单的解决方案。

  1. Create a calculated field called "Positive Rounds per User" using the below formula:使用以下公式创建一个名为“Positive Rounds per User”的计算字段:

// counts the number of unique rounds that had positive amounts per user in a city // 计算一个城市中每个用户具有正数的唯一回合数

{ FIXED [User], [City]: COUNTD(IIF([Amount]>0, [Round], NULL))} { FIXED [用户], [城市]: COUNTD(IIF([Amount]>0, [Round], NULL))}

  1. You can use the above to create another calculated field called "unique users":您可以使用上述创建另一个名为“唯一用户”的计算字段:

// unique number of users that have 2 in "Positive Rounds per User" field // 在“Positive Rounds per User”字段中有 2 的唯一用户数

COUNTD(IIF([Positive Rounds per User]=2, [User], NULL)) COUNTD(IIF([每个用户的正数]=2, [用户], NULL))

You can combine the calculation of 1 and 2 into one but it gets complex to read so better to split them up您可以将 1 和 2 的计算合二为一,但阅读起来会很复杂,因此最好将它们分开

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM