Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Select case

Hi,

I'm trying to convert this case code to Qlikview, could I please get assistance.

CASE

  when MAC_CODE = 963 then ''SNL''

  Else ''MLOAN''

END as PRODUCT_CODE

CASE when REGISTRATION_MONTH_CODE = ''NOTREG''

  then ''N''

  else

  CASE when ( year(INFORMATION_DATE)*100 + month(INFORMATION_DATE) )

  else ''N''

  END as  REG_LAST_3MONTHS_IND

CASE when FINAL_ML_AMT <= 50000   then  ''A''

  when FINAL_ML_AMT <= 100000  then  ''B''

  when FINAL_ML_AMT <= 150000  then  ''C''

  when FINAL_ML_AMT <= 350000  then  ''D''

  when FINAL_ML_AMT <= 700000  then  ''E''

  else ''F''

END as MLOANS_BANDS_CODE

1 Solution

Accepted Solutions
sinanozdemir
Specialist III
Specialist III

Depends on where you want to accomplish this, in the front-end or in the back-end (load script)?

View solution in original post

12 Replies
sinanozdemir
Specialist III
Specialist III

Hi,

Try this:

LOAD

     If(MAC_CODE = 963, 'SNL', 'MLOAN') As PRODUCT_CODE,

     If(FINAL_ML_AMT <= 50000, 'A',

          If(FINAL_ML_AMT <= 100000, 'B',

               If(FINAL_ML_AMT <= 150000, 'C',

                    If(FINAL_ML_AMT <= 350000, 'D',

                         If(FINAL_ML_AMT <= 700000, 'E', 'F'

                            ))))) As MLOANS_BANDS_CODE

You can put the rest within an IF statement like the above

Not applicable
Author

Thanks a lot, i will try it out now

sinanozdemir
Specialist III
Specialist III

Yeah, sure.

I think you are missing a condition in the second CASE scenario:

Capture.PNG

Not applicable
Author

I made a mistake, heres the original code:

CASE

  when MAC_CODE = 963 then ''SNL''

  Else ''MLOAN''

END as PRODUCT_CODE

CASE

  when REGISTRATION_MONTH_CODE = ''NOTREG'' then ''N''

  else

  CASE

  when (year(INFORMATION_DATE)*100 + month(INFORMATION_DATE))

  else ''N''

  end

END as  REG_LAST_3MONTHS_IND

CASE

  when FINAL_ML_AMT <= 50000 then  ''A''

  when FINAL_ML_AMT <= 100000 then  ''B''

  when FINAL_ML_AMT <= 150000  then  ''C''

  when FINAL_ML_AMT <= 350000  then  ''D''

  when FINAL_ML_AMT <= 700000  then  ''E''

  else ''F''

END as MLOANS_BANDS_CODE

sinanozdemir
Specialist III
Specialist III

You are missing a "then" after the case statement:

Capture.PNG

Not applicable
Author

Oh sorry about that, I will resend it again,

Tell me, If want to put a sum on that nested if statement, how do i go about it?

sinanozdemir
Specialist III
Specialist III

You can sum two columns like the below:

If(Column1 + Column2 <= 10000, 'True', 'False')

When you use the aggregate version of it, Sum():

If(Sum(Column1) <= 1000, 'True', 'False')

Then you need to use Group By in the load script.

Not applicable
Author

Thanks a lot,

Set analysis cant replace the nested if?

sinanozdemir
Specialist III
Specialist III

Depends on where you want to accomplish this, in the front-end or in the back-end (load script)?