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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
RMQLIKUSER
Contributor II
Contributor II

Range sum below with a flag condition

I am having trouble calculating the below logic, Here is the input file.

The output should calculate the sum of mins till the next flag occurs in the column.

For example, the first occurrence of flag is at 544 key so the output should be 26.61+0+0+0.333 till the next occurrence.

Input File:

RMQLIKUSER_0-1652365741271.png

Output File:

RMQLIKUSER_1-1652365778795.png

 

Labels (6)
1 Reply
vchuprina
Specialist
Specialist

Hi,

Try following

First, create a new unique Flag, just combine the old flag with the Key field.

After the first step, you will have 

vchuprina_0-1652524481293.png

Then populate missing values in the New Flag field by using the Peek function

vchuprina_1-1652524598224.png

After this, you can use the expression below to get the necessary results on UI

Aggr(SUM(Time), NewFlag) 

vchuprina_2-1652524708603.png

Also, you can add an additional transformation step in the script and calculate the sum 

DATATMP:
LOAD
     If(IsNull(NewFlag), Peek(NewFlag), NewFlag) AS NewFlag,
     Flag,
     Key,
     Time;
LOAD
     *,
     If(Len(Trim(Flag)) >0, Flag&Key) AS NewFlag; //in my example I use inline-table, so Flag without value is empty space if you have nulls change the condition
LOAD * Inline[
Key, Time, Flag
544, 26.6166666, T
568, 0,
569, 0,
570, 0.3333333
1045,3.0333333, T
1048,16.5166666,
1064,3.1166666,
1067,0.3333333,
];

// Additional step to calculate Time in script

DATA:
LOAD
     SUM(Time) AS NewTime,
     Min(Key) AS Key
Resident DATATMP
Group By NewFlag;

vchuprina_3-1652524989845.png

Regards,

Vitalii
 

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").