Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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:
Output File:
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
Then populate missing values in the New Flag field by using the Peek function
After this, you can use the expression below to get the necessary results on UI
Aggr(SUM(Time), NewFlag)
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;
Regards,
Vitalii