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: 
entsh
Contributor II
Contributor II

SUM BETWEEN TO DATES WITH CONDITION

HELLO

please see table1 and table 2

TABLE1:

NAMESTARTFINISHSUM NUMBERS (FOR DATES IN TABLE 2 BETWEEN START AND FINISH IN TABLE1)
A2020/01/012020/01/15180
B2020/02/012020/02/20100
C2020/02/012020/02/250

 

TABLE2:

NAMEDATENUMBER
A2020/01/0250
A2020/01/0260
A2020/01/0340
A2020/01/1430
A2020/01/1620
B2020/02/1555
B2020/02/1645
C2020/04/0530

 

i want to add "sum" field in table1

formula : sum numbers in TABLE2 that DATE between START and FINISH IN TABLE1

WOULD U PLEASE ATTACH QLIKVIEW FILE? (QVW FORMAT)

 

2 Solutions

Accepted Solutions
MayilVahanan

HI @entsh 

PFA

Intevalmatch concept will help you for this requirement.

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

Try this,

tab1:
LOAD * INLINE [
    NAME, START, FINISH
    A, 2020/01/01, 2020/01/15
    B, 2020/02/01, 2020/02/20
    C, 2020/02/01, 2020/02/25
];

Left Join(tab1)
LOAD * INLINE [
    NAME, DATE, NUMBER
    A, 2020/01/02, 50
    A, 2020/01/02, 60
    A, 2020/01/03, 40
    A, 2020/01/14, 30
    A, 2020/01/16, 20
    B, 2020/02/15, 55
    B, 2020/02/16, 45
    C, 2020/04/05, 30
];

Left Join(tab1)
LOAD NAME, Sum(If(DATE>=START And DATE<=FINISH,NUMBER)) As Sum
Resident tab1
Group By NAME;

View solution in original post

8 Replies
JuanGerardo
Partner - Specialist
Partner - Specialist

Hi @entsh , you can try following expression:

Sum({<DATE = {">=$(=Min(START))<=$(=Max(FINISH))"}>}  NUMBER)

JG

 

entsh
Contributor II
Contributor II
Author

IT DOESNT WORK ! JUST SHOW 0 !

WOULD U PLEASE ATTACH QLIKVIEW FILE? (QVW FORMAT)

JuanGerardo
Partner - Specialist
Partner - Specialist

Hi, I have no file, just giving you guidance. Probably it is because of the date format, you can try:

Sum({<DATE = {">='$(=Date(Min(START), 'YYYY/MM/DD'))'<='$(=Date(Max(FINISH)), 'YYYY/MM/DD')'"}>}  NUMBER)

JG

entsh
Contributor II
Contributor II
Author

THANKS A LOT BUT IT SHOWS 0 !

mfchmielowski
Creator II
Creator II

Hi. I'll not give you the qvw file, sorry. You're looking for interval match function. Documentation

Adapt second example usage. 

MayilVahanan

HI @entsh 

PFA

Intevalmatch concept will help you for this requirement.

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

Try this,

tab1:
LOAD * INLINE [
    NAME, START, FINISH
    A, 2020/01/01, 2020/01/15
    B, 2020/02/01, 2020/02/20
    C, 2020/02/01, 2020/02/25
];

Left Join(tab1)
LOAD * INLINE [
    NAME, DATE, NUMBER
    A, 2020/01/02, 50
    A, 2020/01/02, 60
    A, 2020/01/03, 40
    A, 2020/01/14, 30
    A, 2020/01/16, 20
    B, 2020/02/15, 55
    B, 2020/02/16, 45
    C, 2020/04/05, 30
];

Left Join(tab1)
LOAD NAME, Sum(If(DATE>=START And DATE<=FINISH,NUMBER)) As Sum
Resident tab1
Group By NAME;
Saravanan_Desingh

Output:

commQV66.PNG