Tableau - Error when COUNT boolean T/F - tableau-api

My goal here is to count the # of True, False and NULL per day using my boolean calculation. Next step would be to calculate the percentage of each T, F, N with overall day.
Below is the visualization I would like to achieve but instead of blue dots, I would need the count of them in number.
Initially, I tried
IF [boolean] THEN 1 ELSE 0 END
But only changing from True to 1, False to 0 and missing the NULL - not counting:
I also tried different Calculated Fields to get the count of it but always getting the same error:
SUM(IF [Field]=TRUE then 1 else 0 end)
COUNT(IF [Field]=TRUE then [ID] end)
ERROR:
Could someone please assist me with a Calculate Field or any other solution where I could get a count of T, F, and NULL that would also assist me with the percentage?
Thank you

You're working too hard.
Just put SUM(Number of Records) on one shelf with DAY(Disconnected ...) on another, with the Boolean field that classifies data rows as > 0 or not on some other shelf, such as Color. No need for a table calc.
Here is an image of a solution posted at https://community.tableau.com/message/601862#601862

Related

Using case expressions in a calculated column postgresql

Edited to provide sample data
I am trying to create a calculated column that sums 2 other columns, which should be easy. However, some values in both of the columns are null, so I want to use a case expression to replace null values in both columns with 0s and then add up the resulting values. The other complicating factor is that the second column contains text values with commas that need to be converted to numerical before I can add them. What I am currently trying to do is:
SELECT (case when pm."PS" is null then 0 else pm."PS" end) + (case when pm."PS-PREV1" is null then 0 else replace(pm."PS-PREV1", ',', '')::numeric end) AS "Sales"
FROM pm
Sample data:
PS
PS-PREV1
20000
null
30000
20,000
null
null
null
30,000
Desired output:
output
20000
50000
0
30000
This is just returning the value of the 1st column without adding in the second column. Where am I going wrong? Am I overthinking this?
your code should work , however you can write it a little bit more clean:
SELECT COALESCE(pm."PS",0)
+ COALESCE(replace(pm."PS-PREV1", ',', '')::numeric,0) AS "Sales"
FROM pm

Tableau create unique max date

I Need to get the Unique value of Max([Date]).
I have this calculation for max date:
{ FIXED [City] : Max([Date]) }
Count :
IF[Max Date (Last Street)]= [Date]
THEN [Count Record]
Else 0
END
For Example:
City Date Street I get (Count) I Want (Count)
Miami 01/01/2019 1st 0 0
Miami 01/02/2019 2nd 0 0
Miami 01/03/2019 3rd 1 0
Miami 01/03/2019 4th 1 1
This would be a good situation to mix LOD calculations and Table Calculations. Your initial LOD function looks good, as it will find the complete max date per each city. From there, you can apply the concept of the calculated field you already have started and add a Table Calculation (Last()):
IF ATTR([Max Date (Last Street)]) = ATTR([Date])
AND LAST() == 0
THEN [Count Record]
Else 0
END
Note that the other portions of the calculated field are wrapped in ATTR() to make them into aggregations.
Once you add additional cities back into the data, you'll have to edit the table calculation by Right clicking on table calculation on view > Edit Table Calculation...
Take note of the fact that Specific Dimensions is selected and Restarting Every is changed to "City"
Final product should look like this:
Alternative Method:
If you'd like to purely use LODs and your street names always contain unique ascending numbers:
If Date = {Fixed [City]: MAX(Date)}
AND REGEXP_EXTRACT([Street],'(\d+)') = {FIXED [City], [Date]:
MAX(REGEXP_EXTRACT([Street],'(\d+)'))}
Then 1
Else 0
END
The above will essentially extract the number from the street then add it as a condition in addition to the MAX(Date) which already exists. Then the you will only get a 1 when both conditions have been met.
The end result will be the same as above.

Count the number of occurrences of Null in a column in tableau

I am relatively new to Tableau and I am wondering if there is a way to calculate null values in a column.
I have a column called Email of type string and want to know how many people have not entered their email i.e. Null.
I tried to create a calculated field with
count(ISNULL([Email]))
But this gives me the total count and not the count of null.
Thanks.
You cannot count NULL since COUNT ignores NULLs.
You can do this, though:
SUM(IF ISNULL([Email]) THEN 1 ELSE 0 END)
Per your additional comment, if you wanted to count where two fields are both NULL then:
SUM(IF ISNULL([Email]) AND ISNULL([Phone]) THEN 1 ELSE 0 END)
You can continue this for any number of fields, as needed.
You can use a filter for that field. Set it to only show you Null values, and set the measure to Count instead of the default Sum.
You can create another column where all null values are set to 1 and anything else to 0, >then count that. It should be something like
>COUNT(IF "null" THEN 1 ELSE 0)
A working syntax for that would had been:
SUM(IF ([Your field] = null) THEN 1
ELSE 0
END)
You can create another column where all null values are set to 1 and anything else to 0, then count that. It should be something like
COUNT(IF "null" THEN 1 ELSE 0)

Crystal Report Cross Tab Calculated Member as text

I'vre created a cross tab report with 2 calculated Member to be able to have the difference between 2 column and the percentage of this difference in CR 2011. What I want to achieve is to create a new column that will display a test depending on the difference value.
Here is a example:
Col1 Col2 Difference Percentage Action
200 0 -200 100 DROPPED
100 100 0 0
0 300 300 100 ADDED
How can create this action column. Calculated member only want some amount value so I cannot output a text in the formula.
Thanks in advance for your help
I finally found the solution.
I can use the Display string formula in the Format Field properties (Common Tab). Here I just check the column and return the string I want otherwise I just format the number.
IF GetColumnGroupIndexOf(CurrentColumnIndex) = 1
AND CurrentColumnIndex =4 THEN
IF GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex) =2 THEN "DROPPED"
ELSE "ADDED"
ELSE
ToText( GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex),2,",")

PostgreSQL tracking votes in a table?

I have a table with a simple up/down vote column which I originally created as a boolean. true is a vote up, false is a vote down. However, I'm not sure how to use aggregate functions to achieve this kind of query result. For example, 5 true rows and 2 false should equal a vote of +3.
I'm thinking that I need to change the column to a smallint with +1 and -1. Is this correct? Is there a better way to query something like this?
No need to change the datatype, simply use a CASE to convert it to -1 and 1, then sum over the expression:
SELECT sum(case when vote_column then 1 else -1 end)
FROM your_table
To properly deal with NULL values, use the following
SELECT sum(case vote_column
when true then 1
when false then -1
else 0
end)
FROM your_table