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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Daryn
Creator
Creator

Sum with multiple conditions giving wrong end value

Hello community,

I am still quite new to Qlik Sense and taught through this great community and some Youtubing!

I am a bit stuck with the following as it doesn't give the result expected for the margin as a  %

To begin I have a margin calculation that works okay.

* Sum of revenue minus costs divided by revenue (*100 for percentage) 

(sum (NETWR) - sum (WAVWR)) / sum ([NETWR])*100

This produces the correct calculation.

 

I then want to apply this across some other charts but with modified selections.

*Sum where Sales organization = UK99 and distribution channel = WO, revenue minus costs divided by revenue (*100 for percentage) 

SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} ((NETWR-WAVWR)/[NETWR]) *100)

I get a result in the millions rather than what I expect at say 40%.

I tried as an IF at the start but with no joy. Is it because I am not summing the individual NETWR, WAVWR etc as in the original Margins calculation? 

Sorry but I am completely stuck on this one 😞 

Help appreciated.

Regards

Daryn 

1 Solution

Accepted Solutions
Or
MVP
MVP

Keep the same Syntax as the original...

(SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} NETWR)

-

SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} WAVWR))

/

(SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} NETWR)

* 100

 

If that isn't right for what you need, you may have to use aggr() for advanced aggregation of the results for a certain dimension level, but if that's the case, you'll need to be more specific about the structure of your object and aggregation requirements.

View solution in original post

4 Replies
Or
MVP
MVP

Your original calculation has three separate sums(), but your new one appears to have all three fields lumped into the same sum(). Try writing the new expression the same way, including the set analysis within each sum.

Daryn
Creator
Creator
Author

Hi OR,

Thanks for the speedy response!

I get an error 'Nested aggregation is not allowed when trying that'?

 

SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} (sum (NETWR) - sum (WAVWR)) / sum (NETWR)*100 )

 

Sorry, await any update.

Thanks Daryn

Or
MVP
MVP

Keep the same Syntax as the original...

(SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} NETWR)

-

SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} WAVWR))

/

(SUM ({< VKORG = {'UK99'}, VTWEG -={'WO'}>} NETWR)

* 100

 

If that isn't right for what you need, you may have to use aggr() for advanced aggregation of the results for a certain dimension level, but if that's the case, you'll need to be more specific about the structure of your object and aggregation requirements.

Daryn
Creator
Creator
Author

Hi OR,

Thank you again, that's got it (though it was missing one more ) before the *). 

Really appreciate your time and speedy responses. 

Regards Daryn