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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sorting issue

Hi,

I have a data set like below.

I want a bar graph and want to limit bars to show only 3 bars with a condition when the gross marging% is higher than 20%.

and secondly i want to sort those bars with an expression - Sum(Revenue).

Gross Margin %(Measurement) - > (Sum(Cost1)+Sum(Cost2)+sum(Cost3))/sum(Revenue)

CustomerName (Dimension) - CustomerName

    

CountryCustomersRevenueCost1Cost2Cost3
IndOrang1004307
RusBharti20005454534
IndRel1001234
RusHP500541135
AmericaOrang234345433335
EMEABharti34237555343
PakRel64576344
BangHP5477343435345
AmericaKelvinator1004543
EMEAwirlpool200068743354
PakOrang1002334
BangBharti5002423223
EMEARel6000464322
MyOrang534543234254
AfganistanBharti45334234
LebanonRel234346
AfganistanHP3454435343111

Regards

Prasanta

23 Replies
Not applicable
Author

Any idea, if i can use the same expression for color coding

like,

sum(cost1+cost2+cost3)/sum(Revenue)>.20, red(), green().

but this is not working.

can you please check if the measurement expression you have written can be used in color expression as well

thanks

Not applicable
Author

Also, i tried to modify the set analysis by adding to get the data for current year.

But it seems like not working.

can you please check

(sum({<YearCD={$(=max(YearCD))},CustomerName = {"=Rank(Sum(Revenue)*(-1*(Sum(Cost1+Cost2+Cost3)/Sum(Revenue)>=0.2)))<=10"}>} Cost1+Cost2+Cost3) / sum(Revenue))

swuehl
MVP
MVP

The color coding seems to work for me (when using an if() statement and the correct field names), but consider that we are only showing bars with margin >= 20% (hence you will probably see only one color):

=if(sum(Cost1+Cost2+Cost3)/sum(Revenue)>.20, red(), green() )

swuehl
MVP
MVP

Prasanta Kumar wrote:

Also, i tried to modify the set analysis by adding to get the data for current year.

But it seems like not working.

can you please check

(sum({<YearCD={$(=max(YearCD))},CustomerName = {"=Rank(Sum(Revenue)*(-1*(Sum(Cost1+Cost2+Cost3)/Sum(Revenue)>=0.2)))<=10"}>} Cost1+Cost2+Cost3) / sum(Revenue))

I don't see this YearCD field and data in your sample app.

Could you upload another sample with appropriate data and your expected result?

swuehl
MVP
MVP

Prasanta Kumar wrote:

this is working. but i am not able to identify, how you limit the bars to 2 in your first bar chart.

But anyway many thanks this set analysis is perfectly working as per my requirement.

This is the expression for the first chart:

sum(

{<Customers *= {"=Rank(Sum(Revenue))<=3 and (Sum(Cost1+Cost2+Cost3)/Sum(Revenue)>=0.2)"}>} Cost1+Cost2+Cost3)

/ sum(Revenue)

The set expression is filtering Customers that fulfill two conditions (combined by AND operator):

a) Top3  Customer  w.r.t. sum(Revenue)

     Rank(Sum(Revenue))<=3

b) Margin >= 20%

     Sum(Cost1+Cost2+Cost3)/Sum(Revenue)>=0.2

Not applicable
Author

Let say, i select a customer from a filter pannel with margin <20%,

so in that case the color should be green . but still its remaining as red.

swuehl
MVP
MVP

Not sure if I understand your issue. Why is this Customer displayed at all (given the filter to only show customers with >= 20% margin)? Which customer are you selecting?

Not applicable
Author

Its like, as a dashboard, on bar graph i want to show 10 customers with margin >20% ordered by revenue.

But want to give that flexibility to users to select a customer from filter pannel and see its gross margin in bargraph irrespective of its gross margin value.

when the gross margin is less than 20%, it should become green,

swuehl
MVP
MVP

And you want to do this in one chart?

Maybe use a conditional function to check if the user selected some customers?

If(GetSelectedCount(Customers),

Sum(Cost1+Cost2+Cost3) / Sum(Revenue),

sum({<Customers *= {"=Rank(Sum(Revenue))<=3 and (Sum(Cost1+Cost2+Cost3)/Sum(Revenue)>=0.2)"}>} Cost1+Cost2+Cost3) / sum(Revenue)

)

Not applicable
Author

yes, this will be one chart