Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Comparing alarm of a period and previous period

Hi,

I would like to know how to refer to a variable from the previous perido. The variable period is defined as a number: 1..36 (like months).

The table is like the following:

customerIdperiodalarm
4260
427

2

4280
4293
4300
4311
4321
4330
4340
4350
4360


I want to show in Qlik the following table

customerIdperiodalarmprevAlarmDifference
427201
428020
429301
430030

How could I calculate prevAlarm? Difference is 1 if the current alarm >0 and the previous was <=0. I have the insight of how to do this, but I need to refer to prevAlarm.

Thank you,

1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this.

Load *, if(alarm >0 and  PrevAlarm <=0, 1,0) as Difference;

Load CustomerID, Period, alarm, previous(alarm) as PrevAlarm

From xyz;

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

2 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this.

Load *, if(alarm >0 and  PrevAlarm <=0, 1,0) as Difference;

Load CustomerID, Period, alarm, previous(alarm) as PrevAlarm

From xyz;

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
vvira1316
Specialist II
Specialist II

Hi,

You will have to change logic for more than one customerId in your data


NoConcatenate
AlarmTmp:
LOAD customerId
,
period
,
alarm
FROM
[..\Data\Test12.xlsx]
(
ooxml, embedded labels, table is Sheet1);
//order by customerId desc, period desc;

NoConcatenate
AlarmData:
LOAD customerId
,
alarm as prevperiodalarm
,
period as prevperiod
,
Peek(alarm, RowNo(), 'AlarmTmp') as periodalarm
,
Peek(period, RowNo(), 'AlarmTmp') as period
// ,If(RowNo()=1, Null(), Peek(alarm, RowNo(), 'AlarmTmp')) as periodalarm
// ,If(RowNo()=1, Null(), Peek(period, RowNo(), 'AlarmTmp')) as period
Resident AlarmTmp;
//order by customerId desc, period desc;

DROP Table AlarmTmp;

AlarmDiff3.PNG

expression

=If(periodalarm > 0 and prevperiodalarm <= 0, 1, 0)