Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ashis
Creator III
Creator III

How to show negative values in bar chart

Hi,

We have a bar chart and my requirement is i need to show all the values(positive and negative) in Y axis and on the same direction.

So i used these code in the expression to get the chart 

=fabs(sum ({$<dim={'abc'}>}xxx)) - converting negative values with absolute values. Please see the screen shot attached, and distinguishing negative values with red color and positive value with green color.

Now i need to show the '-' sign if the value is negative however the chart bar should be on the y axis same direction as it is .

so my requirement is to display the '-' if it is negative. Is there way to do it.

10 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

To display a - sign for the negatives while keepin the absolue value, use a dual:

=Dual(sum ({$<dim={'abc'}>}xxx), fabs(sum ({$<dim={'abc'}>}xxx)))

To set the colours, exapnd the background property of the expressions (click the + next to the expression on the expressions tab). Use the expression:

If(sum ({$<dim={'abc'}>}xxx) < 0, red(), green())

(Adjust your colours to taste) 

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
ashis
Creator III
Creator III
Author

Hi John, Thank you for the quick reply. I changed the formula as you suggested.

=Dual(sum ({$<dim={'abc'}>}xxx), fabs(sum ({$<dim={'abc'}>}xxx)))

 Seems like it did not do anything. I also tried #,##0#,-##0 in number tab . 

Did now work .

ashis
Creator III
Creator III
Author

I also try this in expression 

=num(Dual(sum ({$<dim={'abc'}>}xxx), fabs(sum ({$<dim={'abc'}>}xxx))),'#,##0','-#,##0') and then in number made it expression default. But did not workout. 

Any thought.

 

Thank you,

Vegar
MVP
MVP

The solution presented by @jonathandienst  should work.

image.png

Please see my attached qvw.

ashis
Creator III
Creator III
Author

Hi Vegar,

Thank you for your reply. Yes i see your qvw is working fine. Some how mine is not. Not sure where is the problem though.

Vegar
MVP
MVP

Maybe you could post a limited sample where the problem is still valid?
jonathandienst
Partner - Champion III
Partner - Champion III

The expressions I posted explained the pattern for the expression - they will not work like that, you need to fill out the expression details which you did not supply in your original post.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
ashis
Creator III
Creator III
Author

Hi Jontydpki,

Thank you for your reply. My original expression is

=fabs(sum ({$<L3={'ATTRIB'}>}Sales)) 

Please let me know if you need more info. Thank you again.

Kind regards,

Ashis Sau

Vegar
MVP
MVP

Please see attached new version of my demo app.

image.png