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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
AmyJan25
Contributor II
Contributor II

Trigger in past 5 rows

Hello, 

I am trying to create the final column in my table below that will flag if the Amount < Expenses Trigger has been hit in 5 days prior to the date of that table row. 

Struggling to make this work so any insights would be greatly appreciated 🙂

Date Amount Expenses Amount < Expenses Trigger Trigger Hit in Past 5 Days
18-Apr-25 11,039 10,528 FALSE N
17-Apr-25 11,039 10,528 FALSE N
16-Apr-25 11,020 10,528 FALSE N
15-Apr-25 11,193 10,528 FALSE N
14-Apr-25 11,164 10,528 FALSE N
13-Apr-25 11,028 10,528 FALSE Y
12-Apr-25 11,028 10,528 FALSE Y
11-Apr-25 11,028 10,528 FALSE Y
10-Apr-25 10,870 10,528 FALSE Y
09-Apr-25 11,004 10,528 FALSE Y
08-Apr-25 10,335 10,528 TRUE Y
07-Apr-25 10,375 10,528 TRUE Y
06-Apr-25 10,563 10,528 FALSE N
05-Apr-25 10,563 10,528 FALSE N
04-Apr-25 10,563 10,528 FALSE N
03-Apr-25 10,563 10,528 FALSE N
02-Apr-25 10,563 10,528 FALSE N
01-Apr-25 10,563 10,528 FALSE N
Labels (1)
1 Solution

Accepted Solutions
AmyJan25
Contributor II
Contributor II
Author

I seem to have solved it. Sharing my load script in case it can help anyone else in the future!

DataTable_1:
Load
      Date,
      Amount,
      Expenses,
      if(Expenses > Amount, 'TRUE', 'FALSE')       As Trigger,
      if(Expenses > Amount, '1', '0')       As TriggerSum,
FROM [SourceData];
 
DataTable_2:
Load*,
     TriggerSum +
     Peek('TriggerSum', RowNo() - 1, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 2, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 3, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 4, 'DataTable_1')       As Last5DaysSum
Resident DataTable_1
Order By Date Asc;
Drop Table DataTable_1;
 
DataTable_3:
Load *,
    if(Last5DaysSum >0, 'Y', 'N')      As 5DayTriggerYN
Resident DataTable_2;
Drop Table DataTable_2;

 

View solution in original post

2 Replies
AmyJan25
Contributor II
Contributor II
Author

Thanks! But this seems to be an excel solution rather than a QlikSense solution? 

AmyJan25
Contributor II
Contributor II
Author

I seem to have solved it. Sharing my load script in case it can help anyone else in the future!

DataTable_1:
Load
      Date,
      Amount,
      Expenses,
      if(Expenses > Amount, 'TRUE', 'FALSE')       As Trigger,
      if(Expenses > Amount, '1', '0')       As TriggerSum,
FROM [SourceData];
 
DataTable_2:
Load*,
     TriggerSum +
     Peek('TriggerSum', RowNo() - 1, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 2, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 3, 'DataTable_1') +
     Peek('TriggerSum', RowNo() - 4, 'DataTable_1')       As Last5DaysSum
Resident DataTable_1
Order By Date Asc;
Drop Table DataTable_1;
 
DataTable_3:
Load *,
    if(Last5DaysSum >0, 'Y', 'N')      As 5DayTriggerYN
Resident DataTable_2;
Drop Table DataTable_2;