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: 
Anonymous
Not applicable

Count(Distinct) in an IF statement in the Load script

I am trying to use a Count(Distinct) inside a nested IF statement in the script Load statement,but it does not seem to work. It does work fine as an expression though.

LOAD

IF((PROVIDER='W' AND [PROC CODE] like '7*')OR(PROVIDER='R' AND [PROC CODE] like '7*'),0,

IF([REG FSC]=61,0,

IF((MODIFIER like 'A*') OR (MODIFIER like 'B*') OR (MODIFIER like 'C'),0,

IF((LOC_GROUP='DYL')AND([POST DATE]-[SERV DATE])<='45',0,

IF((LOC_GROUP='HOS')AND([POST DATE]-[SERV DATE])<=3,0,COUNT(DISTINCT(CASE))))))) AS OUTLIER

2 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

In order to use any aggregation functions in the load script, you should add a GROUP BY clause to your load. In order to make it work, you should include all the fields that are used in your IF conditions, as the GROUP BY dimensions.

Alternatively, you can simply assign OUTLIER = CASE when the condition is true and not aggregate in script. Then, you could aggregated in chart using Count(Distinct OUTLIER)

cheers,

Oleg Troyansky

Upgrade your Qlik skills at the Masters Summit for Qlik - coming soon to Munich, Germany!

MK_QSL
MVP
MVP

Load

  *,

  IF(Match(PROVIDER,'W','R') and WildMatch([PROC CODE],'7*'),0

  ,IF([REG FSC] = '61', 0

  ,IF(WildMatch(MODIFIER,'A*','B*','C*'),0

  ,IF(LOC_GROUP = 'DYL' and [POST DATE] - [SERV DATE] <= 45, 0

  ,IF(LOC_GROUP = 'HOS' and [POST DATE] - [SERV DATE] <= 3, 0

  ,COUNT(DISTINCT CASE)

  ))))) as OUTLIER

Group by SOMETHING.....