1

Help with Changing Multiple If Statement to a Case Statement

I need help converting this multiple if statement to a case statement.  Withdrawn and Graduated fields are yes/no.

 

if Withdrawn = 0 and Graduated = 0 then
    let t := 'Enrolled Date';
    days(date('Enrolled Date'), today()) -
    cnt(select 'Academic Breaks' where Date >= t and Date <= today())
else
    if Withdrawn = 1 and Graduated = 0 then
        let t := 'Enrolled Date';
        let y := 'Withdrawal Date';
        days(date('Enrolled Date'), 'Withdrawal Date') -
        cnt(select 'Academic Breaks' where Date >= t and Date <= y)
    else
    if Withdrawn = 0 and Graduated = 1 then
            let t := 'Enrolled Date';
            let x := 'Graduation Date';
            days(date('Enrolled Date'), 'Withdrawal Date') -
            cnt(select 'Academic Breaks' where Date >= t and Date <= x)
        end
    end
end

10 replies

null
    • Dave_Irving
    • 7 mths ago
    • Reported - view

    Or if someone can get this to work for me just using if statements.  That would work to.  I can get it two work with just 2 if statements, but I get no value on any record when using 3 if statements.

    • John_Halls
    • 7 mths ago
    • Reported - view

    Try this

    let t := 'Enrolled Date';
    let y := 'Withdrawal Date';
    let x := 'Graduation Date';
    switch Withdrawn * 1 + Graduated * 2 do
    case 0:
        days(date('Enrolled Date'), today()) -
        cnt(select 'Academic Breaks' where Date >= t and Date <= today())
    case 1:
        days(date('Enrolled Date'), 'Withdrawal Date') -
        cnt(select 'Academic Breaks' where Date >= t and Date <= y)
    case 2:
        days(date('Enrolled Date'), 'Withdrawal Date') -
        cnt(select 'Academic Breaks' where Date >= t and Date <= x)
    end
    

    Regards John

      • Fred
      • 7 mths ago
      • Reported - view

       Very clever way of creating unique instances. I would have created three new variables to do the same thing.

      • John_Halls
      • 7 mths ago
      • Reported - view

       Thanks. It's the same way Multi Choice fields work. If there had been a third field to compare it would be multiplied by 4, etc

    • Dave_Irving
    • 7 mths ago
    • Reported - view
     said:
    switch Withdrawn * 1 + Graduated * 2 do

     I'm confused at this operator. 

    • John_Halls
    • 7 mths ago
    • Reported - view

    Your if statements used two test values which we need to convert to one for the switch

    When Withdrawn = 0 and Graduated = 0, 0 * 1 + 0 * 2 = 0

    When Withdrawn = 1 and Graduated = 0, 1 * 1 + 0 * 2 = 1

    When Withdrawn = 0 and Graduated = 1, 0 * 1 + 1 * 2 = 2

    Regards John

    • Dave_Irving
    • 7 mths ago
    • Reported - view

    I receive invalid operator: booleon * number at line 4....and same with the next *

    • Dave_Irving
    • 7 mths ago
    • Reported - view

    It took some time, but I fixed it.  Had to add number(Withdrawn) and number(Graduated)

    • Fred
    • 7 mths ago
    • Reported - view

    you can also do:

    let t := 'Enrolled Date';
    switch true do
    case Withdrawn = 0 and Graduated = 0:
        days(date('Enrolled Date'), today()) -
        cnt(select 'Academic Breaks' where Date >= t and Date <= today())
    case Withdrawn = 1 and Graduated = 0:
        let y := 'Withdrawal Date';
        days(date('Enrolled Date'), 'Withdrawal Date') -
        cnt(select 'Academic Breaks' where Date >= t and Date <= y)
    case Withdrawn = 0 and Graduated = 1 then
        let x := 'Graduation Date';
        days(date('Enrolled Date'), 'Withdrawal Date') -
        cnt(select 'Academic Breaks' where Date >= t and Date <= x)
    end
    
      • John_Halls
      • 7 mths ago
      • Reported - view

       Of course. Neat!

Content aside

  • 1 Likes
  • 7 mths agoLast active
  • 10Replies
  • 81Views
  • 4 Following