Results 1 to 4 of 4

Thread: If Statement

  1. #1

    Question If Statement

    Morning,

    I'm sure I've over complicated what should be a simple procedure in Lavastorm.

    Essentially I have the following rules that need to be applied to an existing data set. If those rules are met, I want my new column to be populated with a specific string.

    i.e.

    if 'Brand' = "X" and 'Category' = null then NewCategory = "Y" else NewCategory = 'Category'

    Now here is where I'm sure I've over complicated this.

    I want to repeat that rule with several other inputs, and have them all populate the same single column output for NewCategory. I've worked around it in a convoluted way so I thought I'd ask the experts for a better solution.

    if 'Brand' = "X" and 'Category' = null then NewCategory = "Y" else NewCategory = 'Category'
    if 'Brand' = "A" and 'Category' = null then NewCategory = "B" else NewCategory = 'Category'
    if 'Brand' = "B" and 'Category' = null then NewCategory = "Y" else NewCategory = 'Category'
    if 'Brand' = "C" and 'Category' = null then NewCategory = "D" else NewCategory = 'Category'


    Thanks!
    J

  2. #2
    Lavastorm Employee
    Join Date
    Sep 2014
    Location
    London
    Posts
    7

    Default

    Hi jchartrand,

    Thanks for sharing this on the forum. Please give the below a try

    NewCategory = if 'Brand' == "X" and 'Category'.isNull() then "Y"
    else if 'Brand' == "A" and 'Category'.isNull() then "B"
    else if 'Brand' == "B" and 'Category'.isNull() then "Y"
    else if 'Brand' == "C" and 'Category'.isNull() then "D"
    else "NULL"

    emit *, NewCategory

  3. #3

    Default

    Quote Originally Posted by jmok View Post
    Hi jchartrand,

    Thanks for sharing this on the forum. Please give the below a try

    NewCategory = if 'Brand' == "X" and 'Category'.isNull() then "Y"
    else if 'Brand' == "A" and 'Category'.isNull() then "B"
    else if 'Brand' == "B" and 'Category'.isNull() then "Y"
    else if 'Brand' == "C" and 'Category'.isNull() then "D"
    else "NULL"

    emit *, NewCategory
    Yup... definitely made that A LOT harder than it hard to be.

    Thanks for the quick response.

    Cheers,
    J

  4. #4
    Lavastorm Employee
    Join Date
    Sep 2014
    Location
    London
    Posts
    7

    Default

    Glad it works J, let us know if you have any other questions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •