I am trying to write a IIF statement in Tableau to check if a condition passes. If it fails the condition, I want it to show "No values" rather than filtering out the row.
Given below is the IIF statement I am using:
IIF(([Average monthly count] > [Today]),[Average monthly count],"No values in the range")
As mentioned in comments, in Tableau isn't possible to return two different data types in IF or IIF statements, so if you really need to pass a string like "no values in range", you must return a string in true case. This can be done using the function STR as follows:
IIF(([Average monthly count] > [Today]),STR([Average monthly count]),"No values in the range")
Another option may be just return NULL in false case.
IIF(([Average monthly count] > [Today]),[Average monthly count],NULL)
Related
I am trying to add a calculated field in my Data Source connection.
If column 'Order Status' is not equal to 'Shipped' then give the sum of the 'Carton Count' else return 0.
This is what I tried and not sure why it won't let me use this.
IF([Order Status]) != 'Shipped'
THEN SUM([Carton Count])
ELSE 0
END
Tableau doesn't work in a traditional way where we aggregate the the measures in a formula, tableau doesn't allow you to aggregate in a calculated field instead you take measures as it is and use aggreagation at sheet level.
So your formula will be like:
IF([Order Status]) != 'Shipped'
THEN [Carton Count]
ELSE 0
END
When you drag this field on to sheet then aggregation is applied automatically
In my xquery i have the condition to check if (SP_TYPE_CD!="") and (max of the EndDate) in an array and return the EndDate that meets this condition
Request:
`<CMS xmlns="*******************">
<CMSService>
<CMSDetails AccountID="123456" CR="1000">
<SA_INFO_LIST>
<SA_INFO_LISTRow SA_ID="3484598047" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60" StartDate="2018-09-27" EndDate="2018-09-27"/>
<SA_INFO_LISTRow SA_ID="3486640145" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60" StartDate="2018-04-26" EndDate="2018-04-26"/>
<SA_INFO_LISTRow SA_ID="3487463777" ServiceAgreementType="ERES" ServicePointType="3135182884" SP_TYPE_CD="RESE" Status="70" StartDate="2018-04-06" EndDate=""/>
<SA_INFO_LISTRow SA_ID="3482685560" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60"
</SA_INFO_LIST>
</CMSServiceDetails>
</CMSService>
</CMS>
My Xquery:
for $SA_INFO_LISTRow in $StartServiceAllowedResponse/ns2:CMSService/ns2:CMSServiceDetails/ns2:SA_INFO_LIST/ns2:SA_INFO_LISTRow
return
if (($SA_INFO_LISTRow/#SP_TYPE_CD)and fn:max($SA_INFO_LISTRow/#EndDate))
then <ns1:date>{(fn:data($SA_INFO_LISTRow/#EndDate)}</ns1:date>
else ()
I am receiving error message when i run the xquery in jdeveloper
FORG0001: "2018-09-27": invalid value for cast/constructor: {http://www.w3.org/2001/XMLSchema}double: error: double: Invalid double value: 2018-09-27
Unless your query is schema-aware, the #endDate attribute (after atomization) will be xs:untypedAtomic, and the max() function attempts to convert xs:untypedAtomic values to dates. You need to tell the query processor to treat the values as dates, which you can do either by making your query schema-aware, or (more simply) by an explicit cast:
fn:max($SA_INFO_LISTRow/#EndDate/xs:date(.))
However, there are other problems with your query. This condition:
if (($SA_INFO_LISTRow/#SP_TYPE_CD) and fn:max($SA_INFO_LISTRow/#EndDate))
(when corrected) is simply asking whether a maximum date exists, and if there are any dates at all, then there will be a maximum, so this is fairly meaningless.
Also, you say you are looking for entries where #SP_TYPE_CD is not equal to "", but your code is looking for all entries where this attribute exists, regardless of its value.
I'm guessing that you actually want the maximum end date of all entries where #SP_TYPE_CD is not equal to "", and that would be (replacing your entire query)
<ns1:date>
{max(//SA_INFO_LISTRow[#SP_TYPE_CD != '']/#EndDate/xs:date(.))}
</ns1:date>
I want to display the max date when two of the other conditions meet:
I am not sure what is the best way to to it is Tableau calculated field
{
CASE [Due Date] WHEN ([Data Type] = "REAL" and [Source] = "MMA")
THEN
{fixed :max([Due Date])}
ELSE "" END
}
Try defining a calculated field called, say Real_MMA_Due_Date that has a value only under the conditions you want and is null otherwise.
IF [Data Type] = "REAL" and [Source] = "MMA" THEN [Due Date] END
Then you can display Max(Real_MMA_Due_Date) or Min() as needed. Max() ignores nulls, so it will only consider values that pass your IF condition.
That's a flexible approach since it decouples the choice of aggregation function from the IF conditions, allowing you to use the field in multiple ways.
If instead, you need the MAX() embedded in the calculation for some reason, then wrap MAX() around the whole IF statement as in MAX(IF ... END)
I am new to Crystal Rpts...I am using crystal 13 on a windows 7 pro 64-bit. I am trying to write a selection criteria formula for a basic report. Here is what I am trying to say..
if the status.temp_date is empty (null) but the status.perm_date has a date (not null)
then pull all records where that status.perm_date is < the projectedstatus.projected_date and a status.perm_date is in a date range for the projectedstatus.projected_date (projectedstatus.projected_date{?start date} to projectedstatus.projected_date {?end date})
also pull
all records with a projectedstatus.projected_date that is between the projectedstatus.projected_date {?start date} and projectedstatus.projected_date {?end date}
here is what I wrote:
(isnull({status.temp_date}) and not isnull({status.perm_date}) and
{status.perm_date} < {projectedstatus.projected_date} and
{projectedstatus.projected_date} in {?sdate} to {?edate}
this is only returning records with perm.date ....no currently active records with no perm.date and a projected.dates with in the selected date range
so then I tried:
if(isnull({status.temp_date})) and not isnull({status.perm_date}) then
{status.perm_date} < {projectedstatus.projected_date} and
{projectedstatus.projected_date } in {?sdate} to {?edate} and
if (isnull({status.temp_date})) and isnull({status.perm_date}) and not isnull
({projectedstatus.projected_date}) then
{projectedstatus.projected_date} in {?sdate} to {?edate}
now I'm not getting any records.....
any suggestions?
I have used crystal reports long back, Selection formula what ever is written gets checked for each row and if the expression you wrote results in true then that record gets included. if returns false then that record will not be included.
from your code snippet you have to use the if else if conditions so that every condition is getting handled one single boolean true or false should result from there
one more way you can do is, if it is easy to write the the negative case where row should not come then , simply write that condition in if and return false also have else condition with return as true so that for all other conditions rows get selected
like example,
if ((isnull({temp.date}) and not isnull({perm.date}) and (( {perm.date} < {projected.date} and NOT {projected.date} in {?sdate} to {?edate}) OR ({perm.date} > {projected.date}))) then FALSE ELSE TRUE
Please check syntax once.
I need the sum of two database fields. I use this formula field :
{dbfield1}+{dbfield2}
and if dbfield1 and dbfield2 are != from null in database the sum is showing, but if the dbfield1 or dbfield2 are missing(no data) the formula field is not showing.
how can I manage this in Crystal report?
Two options :
Either use the Convert Database Fields to Null option under Report Options, which will convert the numeric field nulls to zero and make your sum work, or
Use the IsNull function in your formula :
If IsNull({dbfield1}) And IsNull({dbfield2}) Then
0
Else If IsNull({dbfield1}) Then
{dbfield2}
Else If IsNull({dbfield2}) Then
{dbfield1}
Else
{dbfield1}+{dbfield2}