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: 
madnanansari
Creator
Creator

Dividing variables bring wrong values

I have defined the below variables in the system:

vSales1

vSales2

vTickets1

vTickets2

vSales = $(vSales1) + $(vSales2)

vTickets = $(vTickets1) + $(vTickets2)

AverageSales = ($(vSales1) + $(vSales2)) / ($(vTickets1)+$(vTickets2))

bring rights results.

where as the below formula brings wrong results:

AverageSales = $(vSales) / $(vTickets)

any idea how to resolve this?

15 Replies
prieper
Master II
Master II

any NULL-values involved?

Peter

prachisangewar
Creator
Creator

Hi,

Try to define the variables as below:

vSales = vSales1 + vSales2

vTickets = vTickets1 + vTickets2

(remove the '$')

You should get the correct result on AverageSales = $(vSales) / $(vTickets) .

Frank_Hartmann
Master II
Master II

i tried to rebuild your issue and for me it works fine.

see attached sample.

hope this helps

Frank_Hartmann
Master II
Master II

I guess you missed the "=" signs

Unbenannt.png

hope this helps

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you have a problem with order of operations. The divide is being done first. Adds parens to control the order.

vSales = ($(vSales1) + $(vSales2))

vTickets = ($(vTickets1) + $(vTickets2))

-Rob

Peter_Cammaert
Partner - Champion III
Partner - Champion III

To easily detect what ROb says is going wrong, try to perform the $-sign substitution yourself and see whether you get wrong precedence or skipped/missing operands in your calculations.

If I do the substitution manually, I get an almost-final expression of = $(vSales) / $(vTickets) into


= $(vSales1) + $(vSales2) / $(vTickets1) + $(vTickets2)


which means that only $(vSales2) (or a part of that variable) is divided by $(vTickets1) because of operator precedence.


Another time-saving suggestion: when using $-sign substitution to assemble expressions, always use too many parentheses. They don't cost you anything but will save you many hours of searching and debugging.


[Edit] Sorry, corrected first name spelling

madnanansari
Creator
Creator
Author

no null values

madnanansari
Creator
Creator
Author

Sorry I wrongly marked this as correct answer. This does not help.

madnanansari
Creator
Creator
Author

$(vSales) and $(vTickets) give the right answer whereas $(vSales) / $(vTickets) bring wrong answer.