I can't seem to find a solution for my issue anywhere, and I hope that I can ask my question correctly here to find an answer:
I am having a problem finding a count of the number of values from only the distinct rows in my dataset.
In my Tableau sheet, I am trying to find the number of cases that are closed as "FCR" - and in the database, this is represented as true or false.
My formula:
SUM(if [IsFCR] = true then 1 else 0 end)
The problem that I am running into is that this is getting the count from all of the rows in my data. But I need represent the total cases, and the FCR value from each of THOSE rows as a distinct count.
As seen in this image: Screen capture of Tableau formula
I am returning 9,000 distinct rows - but 46,000 counts of FCR being true.
Notably, I have tried wrapping my formula in a COUNTD (and it returns 2), in Window_Count (returns 1), among many other guesses as to how I could wrap this calculated field in a way to only count the unique rows.
If only I could use a foreach logic...
Any help that you can give is greatly appreciated.
Related
I'm trying to create a calculated field that sums rows of data where two columns are both missing data. I'm trying this:
SUM( INT( ISNULL( [Column1] ) AND ISNULL( [Column2] ) ) )
However, this gives me very odd results. In one example, I'm getting a result of 882 with the code above where there are a total of 35 rows, where only 10 rows are missing values. I've tried many variations, I'm always getting way too high numbers. The columns in question contains strings, so ZN() won't work. Changing aliases don't seem to make any difference.
What (probably simple) thing am I missing?
Edit: After comments - removing the sum in the CF and then re-adding it as an aggregation makes no difference. Yes, it is a combination of two database tables. The following is the table view without the sum in the CF:
Red is column 2 and pink is column 1. So the CF definitely shows something different for the blank rows, but I can't figure out why it ends up with 99 and 45 (and why sometimes one and sometimes the other). Ideally, I should be getting just 1s and 0s. Green are unique IDs.
AVG function in PostgreSQL ignores NULL values when it calculates the average. But what if I want to count the average value of multiple columns with many NULL values?
All of below commands dont work
AVG(col1,col2,col3)
AVG(col1)+AVG(col2)+AVG(col3) -> sum calculation alone gives wrong value because of null calculation
This question is similar to this Average of multiple columns, but is there any simple solution for PostgreSQL specific case?
I am trying to divide the average value of column1 by the average value of column 2, which will give me an average price from my data. I believe there is a problem with my syntax / structure of my code, or I am making a rookie mistake.
I have searched stack and cannot find many examples of dividing two averaged columns, and checked the postgres documentation.
The individual average query is working fine (as shown here)
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) FROM table1
But when I combine two of them in an attempt to divide, It simply does not work.
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) / (AVG(CAST("Column2" AS numeric(4,2))),2) FROM table1
I am receiving the following error; "ERROR: row comparison operator must yield type boolean, not type numeric". I have tried a few other variations which have mostly given me syntax errors.
I don't know what you are trying to do with your current approach. However, if you want to take the ratio of two averages, you could also just take the ratio of the sums:
SELECT SUM(CAST(Column1 AS numeric(4,2))) / SUM(CAST(Column2 AS numeric(4,2)))
FROM table1;
Note that SUM() just takes a single input, not two inputs. The reason why we can use the sums is that average would normalize both the numerator and denominator by the same amount, which is the number of rows in table1. Hence, this factor just cancels out.
I am trying to create a chart in tableau which will show me the comparison in weeks, i.e. the comparison between the trend from week 1 to week 5.
In simple terms it should be like:
If Verdict = "Not Reversing" THEN count the total number of Verdicts
Else do not count
If IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
Error message shows cannot mix aggregate and non aggregate functions
Assuming your data source has exactly one data row per verdict ... (Always be clear about what one row in your data source represents.)
You could define a calculated field called Number of Non Reversing Verdicts defined as INT([Verdict] = "Non Reversing") That field will have the value 1 for Non Reversing verdicts and 0 otherwise. The INT() function converts its arguments into an integer, and treats TRUE as 1 and FALSE as 0.
You can then plot SUM([Number of Non Reversing Verdicts]) as desired, along with SUM([Number of Records]) to see the total number of verdicts -- or even compute the ratio of the two formatted as a percentage.
For extra credit, you could rename the predefined field [Number of Records] to [Number of Verdicts] for this data source if that helps make it more clear. (BTW, look at the definition of [Number of Records] and make sure you understand why that works)
I am trying to find the difference between 2 columns in tableau. The catch though here is that each column is ranked based on a value. The difference i need is between these 2 ranked columns
The rank is computed using the table calculations rank function. Attaching the picture for more information
I am assuming "current" and "prior" are calculated fields.
Just create a new calculated field, here I'll call it "Result". In this field just minus your one from the other so:
[Current - Prior]
Then pull this new field into your measures values on your sheet.