Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
lsmith48461
Partner - Contributor
Partner - Contributor

Getting a Total Percentage

I have a chart where I want to show quantity delivered  on the due date is or isn't the same as the actual ship date. The Dimension is City. I have two expressions:

Order Qty                                      =sum(OrderQuantity)

and

Order Qty On Time                   =If(DueDate = ShipDate, sum(OrderQuantity), 0)

Everything is fine except when I add a third column for percentage.

% Order Qty On Time              =[Order Qty On Time] / [Order Qty]

The column detail naturally shows either 100% or 0%

The problem is on the Total line where nothing I have tried shows the correct percentage which should be around 85%. I've tried multiple combinations using the AGGR or TOTAL functions, but nothing seems to work.

Suggestions?

See below. 

It's either 

 

Labels (1)
11 Replies
njmaehler
Partner - Creator
Partner - Creator

The problem is that Qlik evaluates each expression / measure at an individual line level. You do NOT have either date at the total line level therefore  you might want a different expression for the top line. 
Best way to achieve this is to use variables and make sure that you use the equals sign in front to ensure the variable disregards the dimension. 
Just throwing a curve ball here because you said it is either 0% or 100% - does that mean you ALWAYS deliver in full and never do part deliveries? Base on your answer, you could either do a count of your dates if always full deliveries or you will need to sum(OrderQuantity) if you do allow partial deliveries. 

Variables:
vOrderQtyTotal   =sum(OrderQuantity)
v
OrderQtyOnTimeTotal   =sum(if([Order Date]=[Ship Date],([Order Quantity]),0))

if(Dimensionality() = 0, //this is the top line where Dimensionality() = 0 - might need to use a pivot table here
              $(vOrderQtyOnTimeTotal) / $(vOrderQtyTotal)
, //this is the else i.e. not the top TOTAL line
              sum(if([Order Date]=[Ship Date],([Order Quantity]),0))   / sum(OrderQuantity)
)

vinieme12
Champion III
Champion III

Try below

 OrderQtyOnTime %

sum(  AGGR( If(DueDate = ShipDate, sum(OrderQuantity), 0) ,  YourChartDimension1,YourChartDimension2) )

/

sum(OrderQuantity) 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.