Forum Discussion

anandmitta's avatar
anandmitta
Helper I
4 years ago
Solved

Custom column based on 2 different columns

Hello community, please excuse me if this scenario has already been answered.

 

I have a table with 4 columns.

IDBookNoCont NoCreated date
12341111122222-Feb-22
23452222 26-Mar-22
3456333334443-Apr-22
4567  12-Mar-22
5678  25-Mar-22
6789 76662-Feb-22
78904444564531-Jan-22

 

Above is the sample data.

 

I want a custom column with values 0, 1, 2 with the respective below conditions.

1) If the date difference is less than 7 days between created date and current date then the custom column should be '0'.

2) If the date difference is 7-12 days between created date and current date, and either of BookNo or ContNo is empty then custom column value should be '1'. If BookNo and ContNo is not empty then '0'.

3) If the date difference is greater than 12 days between created date and current date, and either of BookNo or ContNo is empty then custom column value should be '2'. If BookNo and ContNo is not empty then '0'.

 

Below is the expected result

Current date: 4-Apr-22

IDBookNoCont NoCreated dateCustom Column
12341111122222-Feb-220
23452222 26-Mar-221
3456333334443-Apr-220
4567  12-Mar-222
5678  25-Mar-221
6789 76662-Feb-222
78904444564531-Jan-220

 

I have been trying to do this and I'm getting error when trying to create a custom column based on 2 column values. 

 

Please help me with this.

 

Thanks & Regards,

Anand

 

  • anandmitta , Create a new column like

    New column =

    var _diff = datediff([created_date], today(), day)+1

    return

    Switch(true() ,

    _diff <7, 0 ,

    _diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 0,

    _diff <= 12   , 1,

    _diff > 12 && isblank([Book No]) && isblank([Cont No])   , 0,

    _diff <= 12   , 2,

    0)

  • anandmitta's avatar
    anandmitta
    4 years ago

    Thank you so much amitchandak. It worked 

     

    There was just 1 small correction to the above query. The value should be 1 or 2 if it falls in the specific date range and book no and cont no are empty. where as the above query makes it 0. Below is the corrected query.

     

    New column =

    var _diff = datediff([created_date], today(), day)+1

    return

    Switch(true() ,

    _diff <7, 0 ,

    _diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 1,

    _diff <= 12   , 0,

    _diff > 12 && isblank([Book No]) && isblank([Cont No])   , 2,

    _diff <= 12   , 0,

    0)

2 Replies

  • anandmitta , Create a new column like

    New column =

    var _diff = datediff([created_date], today(), day)+1

    return

    Switch(true() ,

    _diff <7, 0 ,

    _diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 0,

    _diff <= 12   , 1,

    _diff > 12 && isblank([Book No]) && isblank([Cont No])   , 0,

    _diff <= 12   , 2,

    0)

    • anandmitta's avatar
      anandmitta
      Helper I

      Thank you so much amitchandak. It worked 

       

      There was just 1 small correction to the above query. The value should be 1 or 2 if it falls in the specific date range and book no and cont no are empty. where as the above query makes it 0. Below is the corrected query.

       

      New column =

      var _diff = datediff([created_date], today(), day)+1

      return

      Switch(true() ,

      _diff <7, 0 ,

      _diff <= 12 && isblank([Book No]) && isblank([Cont No])   , 1,

      _diff <= 12   , 0,

      _diff > 12 && isblank([Book No]) && isblank([Cont No])   , 2,

      _diff <= 12   , 0,

      0)