Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
entsh
Contributor II
Contributor II

SUM IF WITH CONDITION

HI

PLEASE SEE THE TABLES BELOW:

 

TBL1:

nameSTFNplan
A50070010000
B5006008000
C7009006000

 

TBL2:..

NAMENUMBERTED
A5004000
A5503000
A8003000
B5509000
B6001000
B6501000
C6001000
C6502000

 

IF SUM OF "TED" FOR EACH "NAME" (JUST FOR NUMBERS BETWEEN ST AND FN) IS LARGER THAN PLAN SHOW "OK" ELSE SHOW "NOK"

RESULT

NAMESTATUS
ANOK  (SUM TED FOR NUMBERS BETWEEN ST AND FN=4000+3000=7000<10000
BOK (SUM TED FOR NUMBERS BETWEEN ST AND FN=9000+1000=10000>8000
CNOK (SUM TED FOR NUMBERS BETWEEN ST AND FN=0<6000
2 Solutions

Accepted Solutions
MayilVahanan

HI Entsh

Try with intervalmatch concept for this scenario.

Something like below

T1:
LOAD * INLINE [
NAME, ST, FN, Plan
A, 500, 700, 10000
B, 500, 600, 8000
C, 700, 900, 6000
];

Plan:
Load NAME, Plan Resident T1;

DROP Field Plan From T1;

T2:
LOAD * INLINE [
NAME, NUMBER, TED
A, 500, 4000
A, 550, 3000
A, 800, 3000
B, 550, 9000
B, 600, 1000
B, 650, 1000
C, 600, 1000
C, 650, 2000
];

IntervalMatch(NUMBER, NAME)
LOAD ST, FN, NAME Resident T1;

Join
Load * Resident T1;

Join
Load * Resident T2;

DROP Table T1, T2;

O/p:

MayilVahanan_0-1626188577382.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

Saravanan_Desingh

One more solution,

tab1:
LOAD * INLINE [
NAME, ST, FN, Plan
A, 500, 700, 10000
B, 500, 600, 8000
C, 700, 900, 6000
];

Left Join(tab1)

tab2:
LOAD * INLINE [
NAME, NUMBER, TED
A, 500, 4000
A, 550, 3000
A, 800, 3000
B, 550, 9000
B, 600, 1000
B, 650, 1000
C, 600, 1000
C, 650, 2000
];

Left Join(tab1)
LOAD NAME, If(Sum(If(NUMBER>=ST And NUMBER<=FN,TED))>=Only(Plan),'OK','NOK') As Status
Resident tab1
Group By NAME;

View solution in original post

3 Replies
MayilVahanan

HI Entsh

Try with intervalmatch concept for this scenario.

Something like below

T1:
LOAD * INLINE [
NAME, ST, FN, Plan
A, 500, 700, 10000
B, 500, 600, 8000
C, 700, 900, 6000
];

Plan:
Load NAME, Plan Resident T1;

DROP Field Plan From T1;

T2:
LOAD * INLINE [
NAME, NUMBER, TED
A, 500, 4000
A, 550, 3000
A, 800, 3000
B, 550, 9000
B, 600, 1000
B, 650, 1000
C, 600, 1000
C, 650, 2000
];

IntervalMatch(NUMBER, NAME)
LOAD ST, FN, NAME Resident T1;

Join
Load * Resident T1;

Join
Load * Resident T2;

DROP Table T1, T2;

O/p:

MayilVahanan_0-1626188577382.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Saravanan_Desingh

One more solution,

tab1:
LOAD * INLINE [
NAME, ST, FN, Plan
A, 500, 700, 10000
B, 500, 600, 8000
C, 700, 900, 6000
];

Left Join(tab1)

tab2:
LOAD * INLINE [
NAME, NUMBER, TED
A, 500, 4000
A, 550, 3000
A, 800, 3000
B, 550, 9000
B, 600, 1000
B, 650, 1000
C, 600, 1000
C, 650, 2000
];

Left Join(tab1)
LOAD NAME, If(Sum(If(NUMBER>=ST And NUMBER<=FN,TED))>=Only(Plan),'OK','NOK') As Status
Resident tab1
Group By NAME;
Saravanan_Desingh

Output:

commQV76.PNG