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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count Percentage

Hi Guys,

I have a scenario where Where an Order can go through different statuses during it's life time and each status has a reason.

so as an example.. Order can have status 'On Hold' for reason 'Awaiting Payment' and just like this there are many reasons for being on Hold for being cancelled

I want to calculate the most popular reasons for Order being on Hold or being Cancelled

I have tried following formula in the expression but it is not giving desired   = count(OrderId) / count(total(OrderId))

Percentage.png

Sample QVW attached

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

You want this?

Capture.PNG

Expression used:

Count({<HoldReason = {'*'}>}OrderId)/Count(TOTAL {<HoldReason = {'*'}>} OrderId)

Count({<CancellationReason = {'*'}>}OrderId)/Count(TOTAL {<CancellationReason = {'*'}>} OrderId)

View solution in original post

4 Replies
sunny_talwar
MVP
MVP

You want this?

Capture.PNG

Expression used:

Count({<HoldReason = {'*'}>}OrderId)/Count(TOTAL {<HoldReason = {'*'}>} OrderId)

Count({<CancellationReason = {'*'}>}OrderId)/Count(TOTAL {<CancellationReason = {'*'}>} OrderId)

Not applicable
Author

Try these changes to your expression:

count(OrderId) / count({$<HoldReason={'*'}>} total(OrderId))

count(OrderId) / count({$<CancellationReason={'*'}>} TOTAL (OrderId))

See attached.

They produce this:

cancelled vs held.PNG

Consider using a simpler data-model, only these columns:

  1. Order
  2. Status
  3. Reason

That data-model would allow for clearer and/or simpler solution(s)..  

sunny_talwar
MVP
MVP

Your simpler model made me think that why are we even using OrderId here, why don't we use this:

Count(HoldReason)/Count(TOTAL HoldReason)

and

Count(CancellationReason)/Count(TOTAL CancellationReason)


Capture.PNG

Not applicable
Author

You're right! Of course! But this doesn't even require a simpler model, it works with original model...

The principle is that COUNT() will not COUNT null values, right?

Good idea; best answer so far