简体   繁体   English

在 Tableau 中使用 COUNT 按组计算观察值

[英]Using COUNT in Tableau to count observations by group

Thanks in advance for any advice you can offer!预先感谢您提供的任何建议! I'm building a Tableau dashboard to explore housing affordability and school quality in different neighborhoods in my area.我正在构建一个 Tableau 仪表板来探索我所在地区不同社区的住房负担能力和学校质量。 A user will select their occupation and see a graph of neighborhoods plotted based on school quality and housing affordability.用户将选择他们的职业并查看根据学校质量和住房负担能力绘制的社区图表。 To explore housing affordability, I'm using county level assessor data with the valuation of every property matched to neighborhoods.为了探索住房负担能力,我使用县级评估员数据以及与社区匹配的每个房产的估值。

The goal is to display the percentage of homes in an area that are affordable given the median occupational wages for the job a user selected.目标是根据用户选择的工作的职业工资中位数,显示该地区可负担的房屋百分比。 Right now, I'm trying to use a calculated field with COUNT([Parcels]<[Occupation])/COUNT([Parcels]) , but I need to find a way to count the number of properties in each specific neighborhood below the cut off value.现在,我正在尝试将计算字段与COUNT([Parcels]<[Occupation])/COUNT([Parcels]) ,但我需要找到一种方法来计算下方每个特定社区的房产数量截断值。

Does anyone know of a way to count elements of a particular group in this way in Tableau?有谁知道在 Tableau 中以这种方式计算特定组元素的方法?

I'm on a Mac, using Tableau Desktop, and doing the back end analysis work in R. Thank you!我在 Mac 上,使用 Tableau Desktop,并在 R 中进行后端分析工作。谢谢!

You seem to misunderstand what the function COUNT() does.您似乎误解了函数 COUNT() 的作用。 You are certainly not alone.你当然不是一个人。 Count() behaves in Tableau almost identically to how it does with SQL. Count() 在 Tableau 中的行为与它在 SQL 中的行为几乎相同。

Count([some field]) returns the number of data rows where the value for [some field] is not null. Count([some field]) 返回 [some field] 的值不为空的数据行数。 It does not not return the number of rows where [some field] evaluates to true, or a positive number, or anything else.它不返回的行数,其中[某些领域]的值为true,或正数,或其他任何东西。

If [some field] always has a non-null value, then Count([some field]) is the same as SUM([Number of Records]).如果 [some field] 始终具有非空值,则 Count([some field]) 与 SUM([Number of Records]) 相同。 If [some field] is always null, then Count([some field]) is zero.如果 [some field] 始终为 null,则 Count([some field]) 为零。 Count() is not like Excel's CountIf function. Count() 不像 Excel 的 CountIf 函数。

If you want to count data rows that meet a condition, you could try COUNT(if [condition] then 1 end) Since the missing ELSE case defaults to null values, that expression will count rows where [condition] is true.如果要计算满足条件的数据行,可以尝试COUNT(if [condition] then 1 end)由于缺少的 ELSE 情况默认为​​空值,该表达式将计算 [condition] 为 true 的行。

So one way to get the percentage of affordable homes is count(if [affordable] then 1 end) / count(1) assumes each Data row represents a home.因此,获得可负担房屋百分比的一种方法是count(if [affordable] then 1 end) / count(1)假设每个 Data 行代表一个房屋。 Then format your field to display as a percentage.然后格式化您的字段以显示为百分比。 Another option is to learn to use quick table calcs另一种选择是学习使用快速表计算

If you want to display the number of rows in a given visualized table you could also use SIZE()如果要显示给定可视化表中的行数,也可以使用SIZE()

在此处输入图片说明

Source, official docs: https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#size来源,官方文档: https : //help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#size

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

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