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. 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.
Does anyone know of a way to count elements of a particular group in this way in Tableau?
I'm on a Mac, using Tableau Desktop, and doing the back end analysis work in R. Thank you!
You seem to misunderstand what the function COUNT() does. You are certainly not alone. Count() behaves in Tableau almost identically to how it does with SQL.
Count([some field]) returns the number of data rows where the value for [some field] is not null. It does not not return the number of rows where [some field] evaluates to true, or a positive number, or anything else.
If [some field] always has a non-null value, then Count([some field]) is the same as SUM([Number of Records]). If [some field] is always null, then Count([some field]) is zero. Count() is not like Excel's CountIf function.
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.
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. 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()
Source, official docs:
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#size
Related
am trying to get Previous Sum(of someField) based on a variable value which is an Id.
This is not a table, Im doing a KPI
On Qlik you would do something like:
SUM({<Id={"$(=Max(vVariable),-1))"}>} someField)
But I can not achieve it on Tableau, off course is due to my lack of knowledge, unfortunatelly time is tinking at work and wanted to see if anyone has any input!
Thanks
Assuming you may use a sample input like the Superstore (using sales as metric), this could be what you're looking for:
In red you can see your "variable" which allows you to select a value and in blue you'll find the unique row for the previous value (Order ID sorted).
The first thing you need to to do is creating a parameter based on all the Order ID values:
Then things start to get a bit complicated if you're not familiar with LOD (Level of details) and the order of execution in Tableau, especially for filters.
Assuming that you can get some information on your own (otherwise, feel free to ask), the first thing you nee to to do is to "pre-calculate" the equivalent of a table having a rowe for each Order ID, in which you also have the previous Order ID value.
You can achive this combining Fixed (LOD) and Lookup function, creating this Calculated Field "Lookup Order ID":
LOOKUP( max({ FIXED [Order ID] : MAX([Order ID])}),1)
This is actually just a calculated field that you want to "fix" because you need the filter to act after you have made that previous calculus, and then you shift your data by 1 row backward.
Once you've done that, you just nee to create another calculated field in order to test your parametric value, and it could be something like this "check param":
[Lookup Order ID] = [Order ID param]
Moving this calculated field in the filter section and selecting just "true" values, you'll get that unique rows like in the initial image, showing the previous value (blue) related to the one you select in the parameter drop-down menu (red).
I have two categorical columns "Job Industry Categories" and "Wealth Segment" and I can create a crosstab using "Job Industry Categories" in rows and "Wealth Segment" to count values for each industry.
This is how my crosstab looks like currently:
But I want to dynamically count wealth segment column for each industry and then return the wealth segment with maximum count for each industry.
This is what I want to acheive:
What I have tried:
I have tried using LOD expression to get the max of count of wealth segment for each industry but that returns a non-aggregated value and I am not able to extract the wealth segment label for the corresponding value.
MAX(
{ FIXED [Job Industry Category], [Wealth Segment] : COUNT([Wealth Segment]) }
)
I have also tried using IF THEN statement with LOD Expression but, since LOD expression is a non-aggregated value, it throws error. This is what I tried:
IF
{ FIXED [Job Industry Category], [Wealth Segment] : COUNT([Wealth Segment]) } = MAX(
{ FIXED [Job Industry Category], [Wealth Segment] : COUNT([Wealth Segment]) })
THEN
[Wealth Segment]
END
ERROR: cannot mix aggregate and non-aggregate with this function
Thanks in advance.
You are doing 2-3 things not in the correct way here.
1 Your first screenshot (table) is not your data, but already a crosstab query (called pivot table in excel) so how can you imagine some extra column either in row or in column. (second screenshot). tableau is not a spreadsheet like excel, where you can create rows/columns as per your convenience.
2 Why have you used count(wealth status) as aggregation. Though it will give same values but here you required count of records/data called as number of records in tableau's earlier versions.
3 You have not considered the situation where both counts are equal. (these can very well be equal, can't they?)
If you want you can create a new column altogether (without a cross tab view/viz of course) where you can get name of wealth category having more records than other.
I created some random data to replicate your problem. My data looks like (there are 100 rows) (table name is weal.csv)
Cross-tab looks like
Create a calculated field say Max of Wealth with the following calculation
IF {Fixed [Sector], [Wealth Status]: COUNT([weal.csv])} =
{FIXED [Sector]: MAX({Fixed [Sector], [Wealth Status]: COUNT([weal.csv])})}
then [Wealth Status] END
You can filter out null values from this field and can get desired viz as
Note two results in health sector
My sincere advice to new tableau users - unlearn spreadsheet first
Good luck
I have dummy HR data, and I want to color format via a map the difference in median salary based on groupings of birth year.
I have a quick calc field to separate them into birth year groups:
IF DATE([Date of Birth]) >=#1976# THEN "Group 1"
ELSE "Group 2"
END
Now I want to find the difference between the median salaries for those two groups, but I want to conditionally format them via a map to see where the median salary remained similar or differed a lot.
For instance: Median(Group 1([salary])-Median(Group 2([salary]) would give me a +/- difference and then I'd like that to be colored via a gradient and then outlines via state level detail.
This is probably so easy, but I can't think of how to do it via those groups. Would this be a LOD calc?
Define a calc to return the salary for rows in group 1, and null otherwise. Call it say, Old_Folks_Salary, defined something like if Year([Birth Date]) < 1976 then [Salary] end (If the condition in the if statement is not satisfied, and there is no else clause, the expression returns null.) Define a similar field for the youngsters.
The trick to know is that aggregation functions, like Median, silently ignore null values. It’s as if the null values don’t even exist. So ... You can now express your aggregate calculation as
Median([Old Folks Salary]) - Median([Young Folks Salary])
For extra credit, you can replace the hard coded threshold of 1976 with a parameter, and look for more politically acceptable field names.
This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.
How can I get the second highest value from a field in a calculated field. In excel I would use the large function but there doesn't seem to be a tableau equivalent. I would prefer to do the calculation in Tableau instead of using a pass through function.
Here are two alternatives.
First, if you want the calculation to happen on the data source side, You could write a LOD calculation to find the max of your field, name it myMax
{fixed [My_Dimension1], [My_Dimension2] : max(myField)}
Whether you use fixed, include or exclude scope for the LOD calc depends on how you want to scope your analysis.
Then write a row level that returns the field value if it is less than the LOD calc, and implicitly null otherwise, name myFieldExceptMax
if myField < myMax then myField end
The max of that row level calc would be your answer.
max(myFieldExceptMax)
Alternatively, if you want to operate on the client (tableau) side to find the penultimate aggregated query result, you can use on of the ranking table calc functions, and the filter to only show the second ranking result.