Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
VamsiBhagavathula1

Condition in set analysis.

Hello Guys,

Could someone please tell me how to do a field comparison inside set analysis based on the Qlik calendar?

in my case, one customer has multiple refunds for a order on different dates. Qlik calendar is giving me multiple rows for the refund dates(like cross join) . Out of this i need only the rows where calendar date matches refund date.  After this , I need to make some set analysis.

So, mainly, I want to achieve this Date comparison of calendar date & refund date in set analysis and perform count & sum aggregations.

Please see the screenshot attached file of QVF & screenshot. Please let  me know  how  we can achieve it set analysis.

Screenshot 2023-04-24 at 17.46.23.png

 

Thanks,

Vamsi

 

Labels (6)
3 Solutions

Accepted Solutions
BrunPierre
Partner - Master II
Partner - Master II

As below with Include zero values ​​unchecked.

=Count(Aggr(If(Date = RefundDate and DateType='REFUNDS', REF_AMT), YYYYMM, C_ID, REASON, DateType, RefundDate, Date))

BrunPierre_1-1682363070381.png

View solution in original post

vinieme12
Champion III
Champion III

You need to use a composite key, refer below

///****DATA SECTION****//

Orders:
LOAD *,C_ID&OrderDate as cid_date_key INLINE [
C_ID, OrderDate, AMT
ABC, 2023-01-23, 50
DEF,2023-02-02,60

]
;

REFUNDS:
LOAD *,C_ID&RefundDate as cid_date_key INLINE [
C_ID, RefundDate,REASON,REF_AMT
ABC, 2023-02-01,PART1,10
ABC, 2023-03-10,PART2,20
ABC, 2024-04-01,PART3,10
DEF,2023-04-21,FULL,20

]
;

 

 

///****Common Calendar  SECTION****//

TRACE ------------------------------------------------;
TRACE Creating Calendar;
TRACE ------------------------------------------------;

/* Create Custom Calendars per Fact Table*/

Unqualify *;


ORDER_CALENDAR:
Load
cid_date_key,
OrderDate AS Date,
'ORDERS' AS DateType
Resident Orders;

 

REFUND_CALENDAR:
Load
cid_date_key,
RefundDate as Date,
'REFUNDS' as DateType

//,REASON
Resident REFUNDS;

 

/* Create a Common Calendar to allow filtering all data at once*/
Call Calendar('Date', 'E');

 

 

Measure highlighted

Count({< DateType={'REFUNDS'}>} REF_AMT)

vinieme12_0-1682418207345.png

 

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

VamsiBhagavathula1
Author

Hi @vinieme12 , The key approach fails as the individual calendars couldn't to their respective fact tables.

cid_date_key is not the common key between Orders & refunds. So its creating another cross join.

View solution in original post

22 Replies
BrunPierre
Partner - Master II
Partner - Master II

Count(DISTINCT {$<Date={"=Date=RefundDate"},DateType={'REFUNDS'}>} REF_AMT)

or

Create a flag within the load statement if both date fields originate from the same table.

If(Date = RefundDate, 1, 0) as Flag

Then you could do this instead

Count(DISTINCT {$<Flag={1},DateType={'REFUNDS'}>} REF_AMT)

VamsiBhagavathula1
Author

Thanks @BrunPierre . It doesn't work . Its give me all 0's. Have you tried it within qvf file attached??

BrunPierre
Partner - Master II
Partner - Master II


Count(DISTINCT {$<Date={"=Date=RefundDate"},DateType={'REFUNDS'}>} REF_AMT)

BrunPierre_1-1682358725011.png

VamsiBhagavathula1
Author

@BrunPierre : Thanks again for checking this. It does not  work for  me

Count(DISTINCT {$<Date={"=Date=RefundDate"},DateType={'REFUNDS'}>} REF_AMT)

 

I cannot create flag as well because Date comes from Qlik Torbien calendar and RefundDate comes from Refund table. as they are not coming from same table, So i cannot create a flag. If possible can  you try with my qvf file attached in this post

VamsiBhagavathula1
Author

@BrunPierre : i think it didn't worked on your side either. because in the screenshot which you uploaded you get only 1 row for DEF. What happend to other C_ID"ABC"??

BrunPierre
Partner - Master II
Partner - Master II

As below with Include zero values ​​unchecked.

=Count(Aggr(If(Date = RefundDate and DateType='REFUNDS', REF_AMT), YYYYMM, C_ID, REASON, DateType, RefundDate, Date))

BrunPierre_1-1682363070381.png

VamsiBhagavathula1
Author

@BrunPierre : wow, Thanks a lot . It seems to be working for count. how could i do sum with same conditions. but in SUM i need to sum up refund amounts. Can you please help here as well ??

BrunPierre
Partner - Master II
Partner - Master II

=Sum(Aggr(If(Date = RefundDate and DateType='REFUNDS', [Refund Amount]), YYYYMM, C_ID, REASON, DateType, RefundDate, Date))

vinieme12
Champion III
Champion III

i would prefer creating a canonical calendar to simplify such expression,

this can be simplified to something like below

 

=sum({<datetype={'refunddate'}>}refundamount)

https://community.qlik.com/t5/Design/Canonical-Date/ba-p/1463578

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.