Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
lawrance
Creator II
Creator II

Compare and Calculate the Values from Previous Row

Hi All,

How to compare and calculate the below scenarios.

Table 1:

Total
5000

Table 2:

Actual
100
200
300

I need to achieve the below calculation in QlikView Script.

Final Table

RemainingCalculations
4900Total(5000) - Actual(100)
4700Remaining(4900) - Actual(200)
4400Remaining() - Actual(300)

Thanks,

Lawrance A

1 Solution

Accepted Solutions
vishsaggi
Champion III
Champion III

Try this?

Total:

LOAD * INLINE [

Total

5000

];

Concatenate(Total)

Actual:

LOAD *, RecNo() AS RowCnt INLINE [

Actual

100

200

300

];

LET value = NoOfRows('Total');

NoConcatenate

TotalCount:

LOAD RowCnt, Actual, IF(RowCnt < '$(value)', Peek(Total) - Actual, Total) AS Total

Resident Total;

DROP TABLE Total;

NoConcatenate

Final:

LOAD *

Resident TotalCount

WHERE Len(Trim(RowCnt)) <> 0;

Drop Table TotalCount;

View solution in original post

7 Replies
lawrance
Creator II
Creator II
Author

Hi all,

Could someone please help me to achieve the above mentioned scenario?

Thanks,

Lawrance A

vvira1316
Specialist II
Specialist II

here you go

vishsaggi
Champion III
Champion III

Try this?

Total:

LOAD * INLINE [

Total

5000

];

Concatenate(Total)

Actual:

LOAD *, RecNo() AS RowCnt INLINE [

Actual

100

200

300

];

LET value = NoOfRows('Total');

NoConcatenate

TotalCount:

LOAD RowCnt, Actual, IF(RowCnt < '$(value)', Peek(Total) - Actual, Total) AS Total

Resident Total;

DROP TABLE Total;

NoConcatenate

Final:

LOAD *

Resident TotalCount

WHERE Len(Trim(RowCnt)) <> 0;

Drop Table TotalCount;

lawrance
Creator II
Creator II
Author

Hi Vijay,

Could you please tell me how to convert the below expression into QlikView Script.

=If(RowNo() = 1, (TotalValue - Max({<Seq={'1'}>}ActualValue)), (TotalValue - RangeSum(Above(TOTAL RangeSum(ActualValue), 0, RowNo(TOTAL)))))


Thanks,

Lawrance A

vvira1316
Specialist II
Specialist II

Attached is QlikView file. Do you mean in QlikSense

vvira1316
Specialist II
Specialist II

Oh You want to do in script instead of in chart

sujeetsingh
Master III
Master III

Hey Seems Vishwa has given you the code with slight play and alters you can make it more dynamic. Like trying sum of the field to calculate totals.