Count if "YES" in 1 field or another in Tablean - tableau-api

I am trying to create a calculated field in tableau that will count if one field OR another contains 'yes' - and then add the YES's together as a value.
I have tried CASE WHEN, IF, COUNTIF but I am having trouble as I have to have the OR in the calculated field.
Here is my last attempt that also failed:
COUNTIF([M-CROSSC (Cross Country)]) = 'YES' OR ([W-CROSSC (Cross Country)])= 'YES' THEN '1' END

Try this. Put the if statement inside the count().
COUNT(IF [M-CROSSC (Cross Country)] = 'YES' OR ([W-CROSSC (Cross Country)]= 'YES' THEN '1' END)
edited to remove extra ')' after each dimension.

Related

How to create a drop down or multiple select filter in dashboard that will filter all worksheets?

I have null and non-null values in my dataset. I would like to create a drop down which will consist of -Display All, Null or Non-Null values. This should filter the dataset so that all worksheets in the dashboard are filtered out based on it. How shall I proceed?
A parameter will help you accomplish this.
Create... > Parameter > String > List > ["All", "Non-Null", "Null"]
From there, create a calculated field which references the parameter.
If [Parameter] = "Non-Null" Then
(If IsNull([Nullable Field]) = False Then 'Show' Else 'Hide' End)
ElseIf [Parameter] = "Null" Then
(If IsNull([Nullable Field]) = True Then 'Show' Else 'Hide' End)
Else 'Show'
End
Finally, place the newly created calculated field on filter and select only 'Show.' To filter all worksheets, right click on the filter and select Apply to worksheets > All using related datasource or specific sheets of your choosing.

CASE WHEN in Oracle SQL Developer in join statement

I wrote this snippet of code here in Oracle SQL Developer but I don't know how to use a CASE WHEN so that when k.QUARANTINED = 0, display 'No', else if k.QUARANTINED = 1 display 'Yes'. This column is always 0 or 1.
select
s.NAME as "Shipment ID"
,k.STATUS_ID as "Status"
,k.EXPIRATION
,k.DISDATE
,u.SCR_NO as "Patient No"
,k.QUARANTINED
,k.PREVIOUS_STATUS_ID
,k.SORT_KEY as "Sort Order"
from KIT k
left join SHIPMENT s on s.ID = k.SHIPMENT_ID
left join USR u on u.PAT_ID = k.PAT_ID;
I tried a couple of times but kept getting errors most likely since I don't know how write the syntax correctly or maybe I have to rewrite this completely differently? I'd like to keep the order of the columns the same. I just would like to see 'Yes' or 'No' for k.Quarantined instead of 0 or 1 returned in the result. :)
SELECT
S.name AS "shipment ID",
K.status_id AS "status",
K.expiration,
K.disdate,
U.scr_no AS "Patient No",
K.quarantined,
CASE k.quarantined
WHEN 0 THEN 'No'
WHEN 1 THEN 'Yes'
ELSE 'Missing or Null'
END AS "quarantine status case example 1",
CASE
WHEN k.quarantined = 0
THEN 'No'
WHEN k.quarantined = 1
THEN 'Yes'
ELSE 'Missing or Null'
END AS "quarantine status case example 2",
K.previous_status_id,
K.sort_key AS "sort order",
FROM Kit K
LEFT JOIN Shipment S
ON K.shipment_id = S.id
LEFT JOIN USR U
ON K.pat_id = U.pat_id
ORDER BY
K.sort_key ASC
;
Two examples of CASE above. The first example is used when you are evaluating a single column/variable.
The second example is used for testing multiple conditions.
When using the second example of CASE statements, it is important to understand that CASE will return the result for the first condition that evaluates TRUE. When using complex logic, sometimes a developer may (inadvertently) have overlapping logic where multiple conditions can be satisfied. When unexpected results from CASE occur, it is important to go back and reevaluate the statement from the top down.
If you are absolutely sure that K.quarantined cannot be NULL and it can only be 0 or one (research the table DDL for check constraints) then you can remove or comment out the ELSE clause on the CASE statements--but it is generally good practice to always have an ELSE clause for consistency. You can have it simply state "ELSE NULL" if you do not ever expect anything other than what's described in your CASE statement.
Lastly, be sure to make sure to identify whether K.quarantined is numeric or text (check table DDL). If it is actually storing text '0' or '1', then should change your literals accordingly--although I think current versions of Oracle are smart enough to do the implicit conversions for you.

Tableau Column Difference - as a dimension

I am looking for difference of two columns in Tableau. I have the formula with me.
IF ATTR([Valuation Profile]) = "Base" THEN
LOOKUP(ZN(SUM([Value])), 1) > - ZN(LOOKUP(SUM([Value]),0)) END
But I get it as a separate column in the columns sections. How do I get that in the rows section? Basically how to get the difference as a dimension?
Please see attached images of what I want and what I have. Apparently, I cannot upload my excel sheet and tableau worksheet here. So I have upload just the screenshots.
What I have - vs - What I want
Tableau Workbook
First off, there is no way that you can generate additional rows for your data in Tableau!
In your case however you could use a workaround and do the following:
Create a calculated field for BASE and one for CSA. The formula should
be IF [Valuation Profile] = 'BASE' THEN [Value] END and IF
[Valuation Profile] = 'CSA' THEN [Value] END respectively
Afterwards you can drag Measure Names onto your rows shelf and
replace the SUM([Value]) with your two newly created calculated fields
that should give you all three measures in different rows in your table
Reference: https://community.tableau.com/message/627171#627171
Use LOD expression to calculate the individual values first.
Create calculated fields 'BASE', 'CSA' and 'CSA-BASE' as below.
BASE:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'BASE' then Value else 0 end ) }
CSA:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'CSA' then Value else 0 end ) }
CSA-BASE
[CSA]-[BASE]
Solution

Nested if else Condition in Crystal report

I have a .rpt file , with a view datasource . I have four parameter which i use in filtering the selection. I have written my selection formula like below.
if ({?actype} <> "All") OR ({?actype} <> "All") OR ({?collectorname} <> "All") OR ({?batchno}<> "All") Then
(
if {?actype} <> "All" Then
{CollectorPerformance.accountType} = {?actype};
if {?collectorname} <> "All" Then
{CollectorPerformance.realname} = {?collectorname};
if {?batchno} <> "All" Then
{CollectorPerformance.batchno} = {?batchno}
and
{CollectorPerformance.clientid} = {?clientid}
and
Date({CollectorPerformance.paymentdate}) >= Date({?from})
and
Date({CollectorPerformance.paymentdate}) <= Date({?to})
)
My issue with the formula, above is that it does not filter by realname and actType. I understand the reason is because the key word "and" is missing . however, it filters the batchno correctly> please how do i make it filter by the remaining two if's ? any help would appreciated.
A selection formula has to be one long valid boolean statement, which is, I think, what you were already suggesting when you say the "and is missing". So in order to fix the first half, you just need to translate those statements into one simplified boolean statement instead of individual statements (those that end in a ';').
({?actype}="All" or {?actype}={CollectorPerformance.accountType})
and
({?collectorname}="All" or {?collectorname}={CollectorPerformance.realname})
and
({?batchno}="All" or {?batchno}={CollectorPerformance.batchno})
...
For each parameter, a user can either select "All" or enter a specific value to filter by. If "All" is selected, that particular portion of the statement (The part that looks like {?Parameter}="All") will evaluate to True and no filtering will be done. Otherwise, only records matching the entered parameter value will return True.

Change Group Name in Crystal Reports to non-Database Value using Formula

I am looking to change the group names in a crystal report to a specified text value not located within the database.
e.g. i have a 'status' field that can either be 'i' or 'a'. I would like these to display as 'inactive' or 'active' in the group headings. The code i currently have in the 'Use a formula as group name' is:
stringvar newGroupName;
if (groupname = "I") THEN newGroupName:= "Inactive" ELSE
if (groupname = "A") THEN newGroupName:= "Active" ELSE
newGroupName:= groupName;
newGroupName
However this says i am passing too few arguments for the groupName reserved word.
Have looked on the net but have not found anything for defining non database names using the groupname function. Any help greatly appreciated.
Just to add, I always add a standard formula to the formula list to calculate the group names :
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown'
Then in the group name formula in the group expert I refer to the formula like {MyGroupName}
This makes it much easier and quicker to edit the names but also will not be lost if you edit the group field (very useful if you have a large amount of code).
Make sure you pick fields from the window they will appear like {table.field} etc
There is no need for variable here just do something like:
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown';