Skip to main content

Hi,

 

I need help in building a KPI using two columns, I'm trying to build the KPI but the code is not getting executed for all the rows i.e. the 2nd condition code is not getting excecuted i'm getting the o/p as Blank .

 

Requirement:

 

image 

Below is my code:

 

CASE WHEN ("CONTROLLER_xlsx_Sheet1"."KEY") = '10' AND COALESCE ("CONTROLLER_xlsx_Sheet1"."CONTR", 'RANDOM_VALUE') != 'A50' OR

("CONTROLLER_xlsx_Sheet1"."KEY") IS NULL AND ("CONTROLLER_xlsx_Sheet1"."CONTR") NOT IN ('A01', 'A02', 'A03') OR

(ISNULL ("CONTROLLER_xlsx_Sheet1"."CONTR") = 1 )THEN 'CLEANSE' ELSE 'PERFECT' END

 

image 

 

Hi @Gundappa Pujari,

 

I think you can improve your code in two ways:

  1. Use brackets to show AND/OR groups
  2. You use two ways for dealing with null values (see marked places), use here the ISNULL() operator

 

CASE

WHEN (("CONTROLLER_xlsx_Sheet1"."KEY") = '10' AND COALESCE("CONTROLLER_xlsx_Sheet1"."CONTR", 'RANDOM_VALUE') != 'A50')

OR (ISNULL ("CONTROLLER_xlsx_Sheet1"."KEY") = 1 AND "CONTROLLER_xlsx_Sheet1"."CONTR" NOT IN ('A01', 'A02', 'A03'))

OR (ISNULL ("CONTROLLER_xlsx_Sheet1"."CONTR") = 1)

THEN 'CLEANSE'

ELSE 'PERFECT'

END

 

I hope this helps.

 

Kind regards,

Jan-peter


Hi @Gundappa Pujari,

 

I think you can improve your code in two ways:

  1. Use brackets to show AND/OR groups
  2. You use two ways for dealing with null values (see marked places), use here the ISNULL() operator

 

CASE

WHEN (("CONTROLLER_xlsx_Sheet1"."KEY") = '10' AND COALESCE("CONTROLLER_xlsx_Sheet1"."CONTR", 'RANDOM_VALUE') != 'A50')

OR (ISNULL ("CONTROLLER_xlsx_Sheet1"."KEY") = 1 AND "CONTROLLER_xlsx_Sheet1"."CONTR" NOT IN ('A01', 'A02', 'A03'))

OR (ISNULL ("CONTROLLER_xlsx_Sheet1"."CONTR") = 1)

THEN 'CLEANSE'

ELSE 'PERFECT'

END

 

I hope this helps.

 

Kind regards,

Jan-peter

Hello @janpeter.van.d ,

 

Thank you for the suggestion. I tried adding the brackets but still 2nd line code is throwing blank output.

 

image.png 

image 

Best Regards,

Gundappa


Hi @Gundappa Pujari ,

I think the problem is the first check. Try the following:

CASE WHEN COALESCE("CONTROLLER_xlsx_Sheet1"."KEY", '-') = '10' AND COALESCE ("CONTROLLER_xlsx_Sheet1"."CONTR", 'RANDOM_VALUE') != 'A50' OR

("CONTROLLER_xlsx_Sheet1"."KEY") IS NULL AND ("CONTROLLER_xlsx_Sheet1"."CONTR") NOT IN ('A01', 'A02', 'A03') OR

(ISNULL ("CONTROLLER_xlsx_Sheet1"."CONTR") = 1 )THEN 'CLEANSE' ELSE 'PERFECT' END


Hi @Gundappa Pujari ,

I think the problem is the first check. Try the following:

CASE WHEN COALESCE("CONTROLLER_xlsx_Sheet1"."KEY", '-') = '10' AND COALESCE ("CONTROLLER_xlsx_Sheet1"."CONTR", 'RANDOM_VALUE') != 'A50' OR

("CONTROLLER_xlsx_Sheet1"."KEY") IS NULL AND ("CONTROLLER_xlsx_Sheet1"."CONTR") NOT IN ('A01', 'A02', 'A03') OR

(ISNULL ("CONTROLLER_xlsx_Sheet1"."CONTR") = 1 )THEN 'CLEANSE' ELSE 'PERFECT' END

THANK YOU @Daniel Diers  for the help 😊


THANK YOU @Daniel Diers  for the help 😊

Did this solve the issue @Gundappa Pujari ?


THANK YOU @Daniel Diers  for the help 😊

Hello Joos,

 

Yes, the above code solved my issue :)


Reply