0

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

null
    • Mad_Amruthur
    • 3 days ago
    • Reported - view

    Found the issue with the nested IF, fixed that, Nested IF works

    Just trying to figure why case or switch won't

    Thanks

    Mad

    • Dvir_Buzaglo
    • 3 days ago
    • Reported - view

    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

    • VP Product Management
    • Ian_Macdonald
    • 3 days ago
    • Reported - view

    Hi 

    Your case statement is missing the hierarchy name, so it will always return false.

    Ian

      • Mad_Amruthur
      • 2 days ago
      • Reported - view

       and 

      Thank you

      I do have the hierarchy, in my attempt to remove the table name I had just removed the text when I pasted above

      Below is the the actual case statement

      The exact same condition works with IF

      case (monthnumber([table.[hbload_date].CurrentMember.caption) = 1, 1,0)

Content aside

  • Status Answered
  • 3 days agoLast active
  • 4Replies
  • 20Views
  • 3 Following