Different Behaviour with IF and SWITCH/CASE
Hello,
I am trying to return measures based on month number
if (monthnumber(table.[hbload_date].CurrentMember.caption) = 1, 1,0)
Returns correctly
When I use case
case (monthnumber(table.CurrentMember.caption) = 1, 1, 0)
IS there a reason for the difference in behaviour ?
When I try to use nested IFs I get an error as below
Compile Error: /opt/apps/Pyramid/repository/general/compile/6f7aaf09-ca78-423d-be35-9980b7a18c9f/plugin.java:17: error: method ifStatement in class PqlCommonFunctions cannot be applied to given types;
return (PqlCommonFunctions.ifStatement(() -> { try { return PqlCommonFunctions.equals(PqlCommonFunctions.monthNumber(p[0]),1D);} catch (Exception e) { throw new RuntimeException(e); } },() -> { try { return 1D;} catch (Exception e) { throw new RuntimeException(e); } },() -> { try { return PqlCommonFunctions.ifStatement(() -> { try { return PqlCommonFunctions.equals(PqlCommonFunctions.monthNumber(p[1]),2D);} catch (Exception e) { throw new RuntimeException(e); } },() -> { try { return 2D;} catch (Exception e) { throw new RuntimeException(e); } },() -> { try { return 0D;} catch (Exception e) { throw new RuntimeException(e); } });} catch (Exception e) { throw new RuntimeException(e); } },() -> { try { return 0D;} catch (Exception e) { throw new RuntimeException(e); } }));
^
required: Supplier<Object>,Supplier<T>,Supplier<T>
found: ()->{ try [...]; } },()->{ try [...]; } },()->{ try [...]; } },()->{ try [...]; } }
reason: cannot infer type-variable(s) T
(actual and formal argument lists differ in length)
where T is a type-variable:
T extends Object declared in method <T>ifStatement(Supplier<Object>,Supplier<T>,Supplier<T>)
1 error
Thanks
Mad
4 replies
-
Found the issue with the nested IF, fixed that, Nested IF works
Just trying to figure why case or switch won't
Thanks
Mad
-
Hi Mad,
The case statement syntax in PQL is as follows:
Case( <Criteria> , <Result> , OPTIONAL <Criteria N> , OPTIONAL <Result N> , OPTIONAL <Default> )
(You can find more information about Case in this Help page )In your case:
case(MonthNumber([data].[dateKey].CurrentMember.caption)=1,1, MonthNumber([data].[dateKey].CurrentMember.caption)=2,2,null)
Dvir
-
Hi
Your case statement is missing the hierarchy name, so it will always return false.
Ian