Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If in Script

This is my script,

load%_BNO,

if(UNIT.GRADEFIX = '' , '', num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))) as Buyer.GCT_Score

  

FROM

[$(QVD_Path)\BUYER_unit.qvd]

(qvd)

group by %_BNO;

It's again saying invalid expression?

Thanks

Gareth

4 Replies
alexandros17
Partner - Champion III
Partner - Champion III

You need an aggregation function for

if(UNIT.GRADEFIX = '' , '', num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))) as Buyer.GCT_Score

something like

Avg(

if(UNIT.GRADEFIX = '' , '', num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))) as Buyer.GCT_Score

)

... even if this expression (the one I've written) doesn't work

sunny_talwar

Try this:

Load%_BNO,

if(UNIT.GRADEFIX = '' , '', num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))) as Buyer.GCT_Score

FROM

[$(QVD_Path)\BUYER_unit.qvd]

(qvd)

Group By %_BNO, UNIT.GRADEFIX;

Anonymous
Not applicable
Author

Thanks sunindia,

What I'm trying to do is if the avg(Unit.Gradefix = '' then make it a 2 otherwise use avg(unit.gradefix)

My expression is below however I don't think it's correct.

Load%_BNO,

if(Avg(UNIT.GRADEFIX = '' , 2 + num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))

,

num(avg(UNIT.M_MILEAGE / 1000) + Avg(UNIT.AGEMONTHS) + Avg(UNIT.GRADEFIX*10) +  Avg(UNIT.CAPCLEAN_ORIG /1000))) as Buyer.GCT_Score

FROM

[$(QVD_Path)\BUYER_unit.qvd]

(qvd)

Group By %_BNO, UNIT.GRADEFIX;

sunny_talwar

Not sure I understand, do you have a sample we can look at?