Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
lain_
Contributor III
Contributor III

Sort a Bar Chart Based on One Value

I have a pivot table like the one below. I am graphing this as a bar chart where N, Y are the x-axis, % is the y-axis and each A% and B% pair are the bars. Is there a way to sort this on the x-axis based on the A% value. For instance, here YA% is 0 whereas NA% is 3. YA% would be to the left of NA% on the x-axis on the bar chart. The NB% and YB% values do not matter in this sort.

  %
NA3
 B1
YA0
 B10
1 Solution

Accepted Solutions
10 Replies
vamsee
Specialist
Specialist

Sorting a pivot table or bar chart can be done under the sort tab. You can sort it by the expression you are using.

Like 

vamsee_0-1593185248855.png

 

if you are looking for something like

vamsee_1-1593185291693.png

 

lain_
Contributor III
Contributor III
Author

Say I have a chart like this. How do I sort it only based on the Desired orange bar, where the orange bars go in descending order. The values of the bar I calculated using an expression that has references to the dimensions. 

 
 
 

graph_img.png

Saravanan_Desingh

Sample data:

tab1:
LOAD 2006+IterNo()-1 As Year,
	Ceil(Rand()*1000) As Desired,
	Ceil(Rand()*1000) As Real
AutoGenerate 1
While IterNo()<=10;

commQV89.PNG

Saravanan_Desingh

Two ways you can do.

Dimension: Year

Expression: Desired and Real

commQV90.PNG

Make Desired as your first Expression.

commQV91.PNG

lain_
Contributor III
Contributor III
Author

To clarify, the problem is that the desired and real values are both generated by the same expression. Please refer to my table on the original post.

vamsee
Specialist
Specialist

Can you please explain how do you have two bars for each year but in the sample data you mentioned only one metric.

It would be easier if you can share your qvw.

lain_
Contributor III
Contributor III
Author

The qvw file is attached with made up data.  How would I sort the chart with b=1 going in descending order?

vamsee
Specialist
Specialist

Unfortunately, I am not able to find a solution to this, for now, you use your expression in sort tab under b

vamsee_0-1593540490682.png

 

 This will work when one year (a) is selected. I tried searching the community for this and couldn't find much useful solutions.

https://community.qlik.com/t5/New-to-QlikView/sort-by-ascending-order-in-bar-chart-with-two-dimensio...

https://community.qlik.com/t5/New-to-Qlik-Sense/Sort-barchart-with-two-dimensions-by-measure/m-p/118...

https://community.qlik.com/t5/New-to-QlikView/2-Dimension-Bar-Chart-Sorting/m-p/966667

With the 3rd option, you will be able to create a chart similar to 

vamsee_0-1593609932379.png

 

lain_
Contributor III
Contributor III
Author

Thank you for the effort. I think my problem is misunderstood. I want the sort the chart by rearranging the values on the x axis. So in the test.qvw I linked earlier, you see that each 'year' (a) is associated with odd numbers from 1 to 9 (b)(excluding 11). How do I sort the year (a) so that the associated 1 values (from b) are going in descending order. So in the test.qvw dashboard I have, it would be sorted  like 2018, 2015, 2017, 2016 in this order. Looking at the blue bars associated with the value 1 (from b), they go in descending order from left to right.  The odd numbers from 1 to 9 (from b) though, should be kept in ascending order.