Calculate count of rows with a dimension value Tableau - tableau-desktop

I want to create a Calculated field to display a Number when the Column/Dimension Outcome_Code == Death.
EX: Out of 1000 rows if 400 rows has Outcome_Code == Death, then I just want to to display a big Number 400.
If I give COUNT(Outcome_Code == 'Death'), it is just just counting total number of rows in the table and showing 1000.
How to create a Calculated field in this case, I don't want a table of value counts, I Just want to display the number, so want a calculated field.

SUM(INT([Outcome_Code] = "Death"))
The innermost expression is a boolean valued expression. The function INT() is a type conversion function that converts boolean values into integers -- evaluating to 1 if the boolean value is True and 0 if it is False. You can leave off the SUM in the calculated field and apply that on the shelf instead if you prefer.
It's worth the effort to realize that boolean expressions are first-class expressions, and can be treated just as naturally as numeric expressions. Other similar expressions are:
MAX([Outcome_Code] = "Death")
which evaluates to True if ANY data records have "Death" for an [Outcome_Code]
and
MIN([Outcome_Code] = "Death")
which evaluates to True if ALL data records have "Death" for an [Outcome_Code]
The last two take advantage of the fact that Tableau treats True as greater than False -- from which you can derive the meaning of MIN and MAX applied to boolean expressions

Related

Filter column that other columns don't have only positive values and don't have only negative values

Currently to make this filter I use this formula:
=FILTER(AC2:AC,
NOT((S2:S>0)*(T2:T>0)*(U2:U>0)*(V2:V>0)*(W2:W>0))*
NOT((S2:S<0)*(T2:T<0)*(U2:U<0)*(V2:V<0)*(W2:W<0))
)
I would like to know if there is a correct and more direct method for this same result.
Your title is a bit confusing, but from your formula my interpretation is that you are filtering out rows from column AC where the corresponding row in columns S:W are all either positive or negative. You could try:
=filter(AC2:AC,byrow(S2:W,lambda(row,abs(sum(sign(row)))<>5)))
SIGN returns 1 for +ve numbers and -1 for -ves. We can get the ABS value of the SUM of SIGNs per row with BYROW, so it's simply a case of FILTERing by those rows not equal to 5 (only observed for all +ves or all -ves in a row).

check if all values returned in filter are equal (google sheets)

I have a row with the following values in each cell from A1 until F1
A,A,A,A,A,A
Then in row 2 I have
A,B,A,A,A,A
Since some columns are empty (no value) I filter the row to get only cells with value:
=filter(A1:F1, A1:F1<>"")
then how can i get a true/false response if all values/strings in the filter array are equal?
Similar answer given here, but that was for a set of arbitrary cells, not a range.
Using range notation:
=COUNTUNIQUE(A1:F1)=1
As implied by the function name, it counts the number of unique values. If there is only one unique value, then we know all the cells are equal. Since COUNTUNIQUE disregards blank values, there is no need to use FILTER first. If you want TRUE for all blanks, change = to <=, as it will return 0 in that case.
If you later decide you do want to consider blank values:
=COLUMNS(UNIQUE(A1:F1, 1))=1
This counts the number of columns returned by UNIQUE(..., 1) (1 means "by column"). If it's 1, then all cells are equal.

Google Sheets SUMIFS different criteria with checkbox

i've the following formula the problem i've is, this isn't working as it should be.
=SUMIFS(E9:14,$I$16:$I,FALSE(),$H$16:$H,G8)
E9:E14 is the part which should be summed up when the checkbox in I16:I = FALSE and if the name matches in H16:H from G8. My problem is I am getting this error
The array arguments of "SUMIFS" vary in size
My question would be, how do I get this exact formula to work? Exactly these areas have to be covered and cannot be changed, otherwise everything else is broken.
EDIT: Added example spreadsheet
https://docs.google.com/spreadsheets/d/1DdTSZAfGTpoeun3k2qqkDMG1jnaUaSz6wgSf2heIIDI/edit?usp=sharing
You need to adjust your ranges. Here's how =SUMIFS() works and then you'll see why you need to adjust the function.
=SUMIFS() looks for ranges and then applies the logic. So when you are telling the function to summarise E9:E14 it interprets it as:
SUM(E9,E10,E11,E12,E13,E14)
provided the following conditions. The conditions will tell the function whether to include each of the components (i.e. E9,...,E14).
Whether a condition is met or not is decided using a simple boolean (true/false) array. This could for example be I9:I14=FALSE which is interpreted as the array
{IF(I9=FALSE),IF(I10=FALSE),...,IF(I14=FALSE)}
resulting in an array similar to this:
{TRUE,TRUE,FALSE,FALSE,FALSE,TRUE}
(assuming the conditions I9, I10 and I14 are met but not the other three. The same is done for the second condition (the values in column H being equal to the value in G8, resulting in another array similar to this:
{TRUE,FALSE,FALSE,TRUE,FALSE,TRUE}
(assuming that only the values in H9, H12 and H14 are equal to G8.
When the function compares the two condition arrays and returns an aggregate array similar to this:
{TRUE,FALSE,FALSE,FALSE,FALSE,TRUE}
because only for the first and the last value the conditions are met. Therefore the =SUM function becomes like this:
SUM(E9,FALSE,FALSE,FALSE,FALSE,E14)
where FALSE = 0 so it returns
=SUM(E9,E14)
Here's where you get into trouble
You try to pass the function conditional arrays that are of a different size to the sum array (E9:E14), in effect asking it to compare apples and the age of your neighbour. What you need to do is to create the calculation you have in column E in a new column in rows 24 down and use that as the sum range in =SUMIFS().

Using COUNTIFS or dcounta instead of multiple COUNTIF

In our Staff timetable, employees can have an "A"shift (which starts at 9am) a "B" shift (which starts at 10:30am) etc.
I need to know how many shifts in total the employees make so what I use now is a multiple times COUNTIF to count the presents of a few arguments in a range of cells
=countif(D8:BM8;A43)+countif(D8:BM8;A44)+countif(D8:BM8;A45)+countif(D8:BM8;A46)++countif(D8:BM8;A47)
Where field A43 contains "A" field A44 cointains "B" etc.
This works perfect, however, I want to have a smarter way to do this, so I tried to use "COUNTIFS" but the result is always 0 and I can't find why
=COUNTIFS(D8:BM8;A43;D8:BM8;A44;D8:BM8;A45;D8:BM8;A46;D8:BM8;A47)
if looks like all arguments are checked with a logical and, but I need a logical and in this case or a solution with dcounta
You are getting a 0 because there is no cell that will meet ALL conditions.
Instead, maybe try something like
=sum(ArrayFormula(--regexmatch(D8:BM8; textjoin("|"; 1; A43:A47))))
Regexmatch returns a boolean, for all the cells in D8:BM8 (true if a match is found, false otherwise). These booleans are converted into 1 and 0 (see the -- in front of the regex). Then all those values are summed.
Copy and paste the code in a module.(VBA)
Select the cell you want to have the results
Use COUNTIFMATCH Function as the usally functions.
The first Argument is the range you want to count. The second Argument is the range with your criteria. e.g
=COUNTIFMATCH($A$1:$A$20,$C$1:$C$3) or =COUNTIFMATCH($A$1:$A$20,($B$1,$D$1))
whatever you need based on your needs.
Option Explicit
Function COUNTIFMATCH(Range As Range, Criteria As Range) As Integer
'counts the number of cells in one range by the values ​​of another range.
Dim datax As Range
Dim rslt As Range
Dim i As Integer
Set rslt = Range
For Each datax In Criteria
i = i + WorksheetFunction.CountIf(rslt, datax)
COUNTIFMATCH = i
Next datax
End Function

Can I filter data in Google Sheets using a condition like not in range?

I'm trying to use Query Language in Google Sheets, but only select data that is not in a range.
I'm able to do that for a specific field, but I'd like to know how to do for a specific range.
May be we can figure-out what is going wrong with your code, if you provide.
The syntax for filter is
FILTER(range, condition1, [condition2, ...])
range - The data to be filtered.
condition1 - A column or row containing true or false values corresponding to the first column or row of range, or an array formula evaluating to true or false.
condition2 ... - [ OPTIONAL ] - Additional rows or columns containing boolean values TRUE or FALSE indicating whether the corresponding row or column in range should pass through FILTER. Can also contain array formula expressions which evaluate to such rows or columns. All conditions must be of the same type (row or column). Mixing row conditions and column conditions is not permitted.
condition arguments must have exactly the same length as range.
Sample Usage
FILTER(A2:B26, A2:A26 > 5, D2:D26 < 10)
FILTER(A2:C5, {TRUE; TRUE; FALSE; TRUE})
FILTER(A2:B10, NOT(ISBLANK(A2:A10)))
https://support.google.com/docs/answer/3093197?hl=en

Resources