Tableau - Condition Logic Bad character Error - conditional-statements

I am currently taking a class on how to use Tableau.
My formula looks like this:
IF(ISNULL([Profit Adj])==False && ISNULL([Budget Adj]) ==FALSE)
then (([Profit Adj] - [Budget Adj]) / [Budget Adj])
else Null
end
I am trying to create a calculated function.
I am getting the following error message on the && part:
Bad Character
Why is this wrong?

IF(ISNULL([Profit Adj])==False AND ISNULL([Budget Adj]) ==FALSE)
then (([Profit Adj] - [Budget Adj]) / [Budget Adj])
else Null
end
Apparently, I am supposed to use AND and not &&.
Now I am good.

Related

PostgreSQL : Operator does not exist: Integer < Interval

I have wrote a query so I can view people who are overdue an order based on their average order dates. The query is to be ran on a PostgreSQL database, and will be executed from a Java process.
However in the line :
CASE WHEN
(max(date_trunc('day', dateordered))-
min(date_trunc('day', dateordered)) ) /
count(distinct dateordered) + 5 <
date_trunc('day',now()) -
max(date_trunc('day', dateordered)) THEN 'ORDEROVERDUE' ELSE
null
END
I receive the error message :
Operator does not exist : integer < interval
I have read a lot of questions which have a similar issue, but none which seem to fix my particular issue.
If I alter my query to this :
CASE WHEN
(max(dateordered::date) - min(dateordered::date) )/
count(distinct dateordered) + 5 <
now()::date - max(dateordered::date) THEN
'ORDEROVERDUE' ELSE null
END
Then it runs on the database, however I can't get this syntax to work in my process in eclipse.
My understanding of SQL is letting me down. I understand the general reason behind the error, but I am unable to create a solution.
Is there a way of altering this line in a way which removes the error and I can still get the desired result?

mdx - how to replace null values with '0' in measures members

In my MDX query I'm using this set of measures in my SELECT statement:
With SET [Selected Measures] AS {
[Measures].[CTR],
[Measures].[Cost],
[Measures].[Clicks]
}
I want in my result to replace the NULL values in '0'.
How to do this?
Try re-defining your measures:
With member [Measures].[Not Null CTR] as Iif( IsEmpty( [Measures].[CTR] ), 0, [Measures].[CTR] )
...
Select { [Measures].[Not Null CTR], ...} on Columns
...
Perhaps changing the measure name for something nicer or renaming the columns back to the original names on the client.
EDIT: If you want to keep the names and the names output by your client are just CTR, etc. (without brackets or the Measures prefix), and you have an extra dimension available somewhere (one that is not used anywhere else in the query), you can define those new members in that extra dimension:
With member [My Other Dim].[CTR] as Iif( IsEmpty( [Measures].[CTR] ), 0, [Measures].[CTR] )
...
Select { [My Other Dim].[CTR], ...} on rows,
...
Definitely not an elegant solution, but it works.
Is it possible to touch upon the cube design? If so you need the open the cube solution, navigate to the "Calculations" tab and add in the below code. Then deploy the changes.
SCOPE([Measures].[CTR]);
IF THIS IS NULL THEN this = 0 END IF;
END SCOPE;
SCOPE([Measures].[Cost]);
IF THIS IS NULL THEN this = 0 END IF;
END SCOPE;
SCOPE([Measures].[Clicks]);
IF THIS IS NULL THEN this = 0 END IF;
END SCOPE;
Based on the first answer, here is an approach that work for the all the measures in the cube :
SCOPE([Measures].MEMBERS);
THIS = IIF(IsEmpty([Measures].CurrentMember) , 0, [Measures].CurrentMember);
END SCOPE;
hope it helps.

Access SQL IF statement failing

Whats wrong with this IF statement? It appears to follow the criteria for a IF, but will not run
SELECT Account, SUM(IF dbo_ADT.type = "wager"
AND - dbo_ADT.amount > 0 then - dbo_ADT.amount
ElseIf dbo_ADT.type = "cancel" THEN
- dbo_ADT.amount elseIf dbo_ADT.type = "winnings"
THEN - dbo_ADT.refund ELSE 0 END IF) AS Handle
FROM dbo_ADT
Access SQL does not support the if...then...elsesyntax (in sql, it's of course supported in vba) but you can use the iif(condition, "value if true", "value if false") to accomplish the same thing if you nest the iifstatements. I think your query should be written as:
SELECT
Account,
SUM(
IIF(
dbo_ADT.type = "wager" AND - dbo_ADT.amount > 0,
- dbo_ADT.amount,
IIF(
dbo_ADT.type = "cancel",
- dbo_ADT.amount,
IIF(dbo_ADT.type = "winnings", dbo_ADT.refund, 0)
)
)
) AS Handle
FROM dbo_ADT
GROUP BY Account
I might have mixed up the nesting (although I believe it's correct), so you'll have to check that you get the expected result (especially for the else condition), but you should get the idea I hope.
I also added a group byclause that's needed when you use aggregate functions.

what's wrong in this code mdx?

I wonder what's wrong in this code?
with
member [CA Espagne] As
((select [Measures].[CA], [[Site].[Pays - Site].[Pays].&[ES]))
select {[Measures].[CA], [CA Espagne]} on 0,
[Temps].[Année - Mois - Jour].[Année].&[20100101].children on 1
from [DistrisysOLAP_Global];
Better to tell us the error you're getting... but I guess you should simply define your calculated member as :
with member [CA Espagne] As ( [Measures].[CA], [[Site].[Pays - Site].[Pays].&[ES] )
then the remaining of the statement looks ok (remove the trailing ; ). Otherwise, here is a page explaining the syntax of the calculated members.

CriteriaAPI: selectCase when then...error in statement

with the following code I get an error in my sql statement:
Expression<Number> difference = queryBuilder.diff(A, B);
Predicate differenceGEtoZero = queryBuilder.ge(difference, new Long(0));
CriteriaBuilder.Case<Number> when = queryBuilder.<Number>selectCase().when(
differenceGEtoZero, difference
);
queryDefinition.select(
queryBuilder.construct(
State.class,
root.get("object"),
queryBuilder.sum(
when.otherwise(new Long(0))
)
)
);
I get this sql statement containing an error in CASE'S THEN part:
SUM(
CASE WHEN ((t1.A - t1.B) >= 0)
THEN ((t1.A - t1.B) >= 0) //'>= 0' should not appear here!!!
ELSE 0
END )
I expected only the difference appearing ((t1.A - t1.B), not again a condition >=0.
I am using this version of the libs: org.apache.openejb:javaee-api:6.0-5 and eclipseLink 2.3.2 as provider
Could you please tell me what's wrong in the code?
Thank you in advance.
Nic
Seems a bug solved by following versions of eclipseLink.
With 2.5.1 everything is working fine.