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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do i use variable's Value in sum of previous year

Dear  All,

           How Do i use use variable's value for set analysis calculation in month & Year.

Variable is BSC

BSC =

sum((if(bil_bil_unit='2',(loa_rate*loa_act_wt)*1000,

//if(bil_bil_unit='3'or bil_bil_unit='2',((loa_rate*loa_act_wt)*1000),

if(bil_bil_unit='3' and loa_rate>10 and loa_rate<100,(loa_rate*loa_act_wt)*1000,

if(bil_bil_unit='3' or bil_bil_unit='5',(loa_rate*loa_act_wt),

if(bil_bil_unit='8' or bil_bil_unit='9' /*or bil_bil_unit='10'*/ or bil_bil_unit='13' or bil_bil_unit='21',(loa_rate*loa_dlv_qty),

//if(bil_bil_unit='10' or itemproduct='9940208',((loa_rate*loa_act_wt)*1000),

if(bil_bil_unit='27' and loa_dlv_qty>0,(loa_rate*loa_dlv_qty),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_cal_wt>0,(loa_rate*loa_cal_wt),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_act_wt>0,(loa_rate*loa_act_wt))))))))))

+

(sum((if(bil_bil_unit='10',(loa_rate*loa_dlv_qty)))))

Tha above formula working for max Year but not for previous year....

Eg :

Current Year = Sum({$<year={$(=max(year))}>}BSC) // its working

Prev Year = =Sum({$<year={$(=max(year)-1)}>}BSC) // giving wrong calculation, its showing me current year calculation.

Can any one help me.

Regards,

Antony.

1 Solution

Accepted Solutions
Not applicable
Author

try this

sum({$<year={$(=max(year))}>}

(if(bil_bil_unit='2',(loa_rate*loa_act_wt)*1000,

if(bil_bil_unit='3' and loa_rate>10 and loa_rate<100,(loa_rate*loa_act_wt)*1000,

if(bil_bil_unit='3' or bil_bil_unit='5',(loa_rate*loa_act_wt),

if(bil_bil_unit='8' or bil_bil_unit='9' or bil_bil_unit='13' or bil_bil_unit='21',(loa_rate*loa_dlv_qty),

if(bil_bil_unit='27' and loa_dlv_qty>0,(loa_rate*loa_dlv_qty),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_cal_wt>0,(loa_rate*loa_cal_wt),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_act_wt>0,(loa_rate*loa_act_wt))))))))))

+

(sum( {$<year={$(=max(year))}>} (if(bil_bil_unit='10',(loa_rate*loa_dlv_qty)))))

and for previous year

sum({$<year={$(=max(year)-1)}>}

(if(bil_bil_unit='2',(loa_rate*loa_act_wt)*1000,

if(bil_bil_unit='3' and loa_rate>10 and loa_rate<100,(loa_rate*loa_act_wt)*1000,

if(bil_bil_unit='3' or bil_bil_unit='5',(loa_rate*loa_act_wt),

if(bil_bil_unit='8' or bil_bil_unit='9' or bil_bil_unit='13' or bil_bil_unit='21',(loa_rate*loa_dlv_qty),

if(bil_bil_unit='27' and loa_dlv_qty>0,(loa_rate*loa_dlv_qty),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_cal_wt>0,(loa_rate*loa_cal_wt),

if(bil_bil_unit='27' or bil_bil_unit='34' and loa_act_wt>0,(loa_rate*loa_act_wt))))))))))

+

(sum( {$<year={$(=max(year)-1)}>} (if(bil_bil_unit='10',(loa_rate*loa_dlv_qty)))))

View solution in original post

18 Replies
somenathroy
Creator III
Creator III

Hi Antony,

Can ypu please attach a demo qvw application.

Regards,

Som

Not applicable
Author

Hi Som,

Thanks for your reply.

        I can not attach the application.

Without sum how do i calcuate the expression.

Regards,

Antony.

Not applicable
Author

Can any one help me to sort out this issue.......

giakoum
Partner - Master II
Partner - Master II

Hi.

put max(year)-1 into a variable and let us know the result. is it what you expect it to be?

Not applicable
Author

i tried but its not working

giakoum
Partner - Master II
Partner - Master II

Is max(year) working? You need to concentrate on that, this may be your problem. If year is not a number for QV, the results you get are wrong.

Not applicable
Author

for qty im taking the same year field only...

=sum({$<year={$(=max(year)-1)}>}Qty) - its working

= sum({$<year={$(=max(year)-1)}>}BSC) - its not working due to variable(BSC)

Not applicable
Author

Hi,

Please By Pass the year vaue first and then write the expression.

ex

Sum({$<year = ,year={$(=max(year)-1)}>}BSC)

i hope this will help.


Not applicable
Author

Hi Pratibha,

          its not working....