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: 
yooyoo
Contributor
Contributor

How to convert to 100% Stacked Bar chart

Hi there, I am new to Qlik and my authority is limited so I can't load the data editor. 

I am trying to set a 100% stacked bar to see gross order % in terms of different sales types. I have checked YouTube videos online and it seems I need to revise the expression like-  Sum(Sales)/Sum (total<Customer Name> Sales). However, I don't think total can be used for my case, as I don't have a field name <Month>. Error in expression : > expected appeared. 

Wondering if anyone can give me some advice. It's very frustrating that I feel like I need to download data to Excel and calculate by myself :(((((

 

Measure: 

Gross order = count(distinct(if([Contract Status]<>'Deleted' or [Contract Status]<>'Unapproved' or [Contract Status]<>'Unapproved never received',[Order Number])))

 

Dimension: 

Month=if([Order Date]>='01/01/2023',if([Order Date]<today(), monthname([Order Date])))

Sales Type = [Sales Type]

Labels (1)
4 Replies
marksouzacosta
Partner - Specialist
Partner - Specialist

Hi @yooyoo,

Let's start cleaning up your code.

For Dimensions use only fields, nothing calculated. Avoid that as much as possible. This is not recommended. So, your fields will be:
Sales Type
Order Month Name *

* Create this field in your Load Script using the expression: monthname([Order Date]) AS [Order Month Name]

 

For your measure, avoid using If statements. Use Set Analysis instead:

Count({< [Contract Status] -= {'Deleted','Unapproved','Unapproved never received'}, [Order Date] = {">=01/01/2023<=$(=Today())"} >} Distinct [Order Number])

 

I'll check the Stacked 100% bar later using those expressions.

 

Regards,

Mark Costa

Read more at Data Voyagers - datavoyagers.net
marksouzacosta
Partner - Specialist
Partner - Specialist

So for the Stacked bar, your measure will look similar to this:

{< [Contract Status] -= {'Deleted','Unapproved','Unapproved never received'}, [Order Date] = {">=01/01/2023<=$(=Today())"} >} Count(Distinct [Order Number]) / Count(TOTAL <[Order Month Name]> Distinct [Order Number])

 Pay special attention to the Set Analysis that is now outside the Measure expressions - meaning it will affect all the measures after it - and the key word TOTAL with the Dimension field that you are aggregating with.

Your bar chart should looks like this:

marksouzacosta_0-1724252955526.png

One quick note, I always recommend studying your numbers in table charts, splitting your measure into multiple ones, so you will see how the numbers are working for each part of your "bigger measure":

marksouzacosta_1-1724253055711.png

So, for the table chart, the measures will be:

{< [Contract Status] -= {'Deleted','Unapproved','Unapproved never received'}, [Order Date] = {">=01/01/2023<=$(=Today())"} >} Count(Distinct [Order Number])
{< [Contract Status] -= {'Deleted','Unapproved','Unapproved never received'}, [Order Date] = {">=01/01/2023<=$(=Today())"} >} Count(TOTAL <[Order Month Name]> Distinct [Order Number])
{< [Contract Status] -= {'Deleted','Unapproved','Unapproved never received'}, [Order Date] = {">=01/01/2023<=$(=Today())"} >} Count(Distinct [Order Number]) / Count(TOTAL <[Order Month Name]> Distinct [Order Number])

 

Regards,

Mark Costa

Read more at Data Voyagers - datavoyagers.net
yooyoo
Contributor
Contributor
Author

Hello Mark,

Thank you so much for your guidance. 

Since my authority is limited, I cannot create a field in the Load Script. 

That's why I was using if statement in dimension:((( 

*quote*

Month=if([Order Date]>='01/01/2023',if([Order Date]<today(), monthname([Order Date])))

*unquote*

Wondering if there is any chance for me to get the same result without loading script:((

 

marksouzacosta
Partner - Specialist
Partner - Specialist

I'm afraid this is not possible, unless someone here in the Community figures out a way to do it.

Can you request someone to add this field for you?
Another possible alternative is to duplicate the current app and change the Load Script to Binary Load the original App. This will allow you to modify the Data Model in any way you need.

Read more at Data Voyagers - datavoyagers.net