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: 
ajsjoshua
Specialist
Specialist

Variance% in Pivot

Hi all,

In pivot chart i am comparing current year sales and previous year sales and their Variance %

I am using this formula for variance %

=(sum({<Year={$(=Max(Year))}>}SalesValue)

-

sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/

sum({<Year={$(=Max(Year)-1)}>}SalesValue)

and in visual cues i selected Upper>=1  and Lower<=0

When current year has vales and last year doesnt have values it displays '-' in variance% but i want to display %values.

PFA for screenshot

Regards,

Joshua.

1 Solution

Accepted Solutions
devarasu07
Master II
Master II

Hi,

try to use Alt function,

like this

method 1:

= alt((sum({<Year={$(=Max(Year))}>}SalesValue) - sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/ sum({<Year={$(=Max(Year)-1)}>}SalesValue),0)


method 2: simplified one,

alt((Column(1) -Column(2))/Column(2),0)

Capture.JPG

Thanks,
Deva

View solution in original post

7 Replies
shiveshsingh
Master
Master

=(sum({<Year={$(=Max(Year))}>}SalesValue)

-

sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/

sum({<Year={$(=Max(Year)-1)}>}SalesValue)

as per your formula, if we don't have value in denominator, result would not be defined. That's why it is coming as '-'

What % are you expecting if denominator is 0 or null?

devarasu07
Master II
Master II

Hi,

try to use Alt function,

like this

method 1:

= alt((sum({<Year={$(=Max(Year))}>}SalesValue) - sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/ sum({<Year={$(=Max(Year)-1)}>}SalesValue),0)


method 2: simplified one,

alt((Column(1) -Column(2))/Column(2),0)

Capture.JPG

Thanks,
Deva

pradosh_thakur
Master II
Master II

We encountered smilar divide by zero issue few months ago. My Client wanted to make it 100% when last year is zero.So it will depend on business requirement.


= alt((sum({<Year={$(=Max(Year))}>}SalesValue) - sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/ sum({<Year={$(=Max(Year)-1)}>}SalesValue),1)

Learning never stops.
ajsjoshua
Specialist
Specialist
Author

Dear Devarasu,

Thanks for ur reply

Its working

= alt((sum({<Year={$(=Max(Year))}>}SalesValue) - sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/ sum({<Year={$(=Max(Year)-1)}>}SalesValue),1)


but when i am setting visual cues as

upper>=21 as green and Lower<=20 as red it display 100% in red but i want to display it in green.

ajsjoshua
Specialist
Specialist
Author

Dear Pradosh,

Thanks for ur reply

Its working

= alt((sum({<Year={$(=Max(Year))}>}SalesValue) - sum({<Year={$(=Max(Year)-1)}>}SalesValue))

/ sum({<Year={$(=Max(Year)-1)}>}SalesValue),1)


but when i am setting visual cues as

upper>=21 as green and Lower<=20 as red it display 100% in red but i want to display it in green.

pradosh_thakur
Master II
Master II

Use 0.21 and 0.20 in place of 21 and 20

Learning never stops.
ajsjoshua
Specialist
Specialist
Author

Dear Pradosh,

THank You.