Skip to main content
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: 
SBDataspark
Creator
Creator

Line chart: How to set the color Green or Red to different measures when above or below zero

Hi there fellow Qlik Sense enthousiasts,

In the attached qvd I've created a small setup of what I'm trying to achieve.
Which is the following.

I have added an inline table with transactions with an amount linked to a date.
The transactions can be positive or negative amounts.
The cumulative sum is plotted in a line chart.

Sebb_0-1645101183588.png

And the color of the line is set by expression:

=If(RangeSum(Above(Sum(Amount),0,RowNo())) < 0
, rgb(255, 0, 0)
, rgb(48, 122, 66)
)

So far pretty straight forward.

To manipulate the cumulative sum for the amounts per month I've added a variable input field.

Sebb_1-1645101406187.png

When you put in a particular amount a second line is created to plot the "Amount + Additional amount" with expression: RangeSum(Above(Sum(Amount),0,RowNo())) + $(vAdditionalAmount)

Sebb_2-1645101549267.png

As you can see the two lines are colored the same way.

I've tried numerous things to get each line to color individually red or green when it's below or above the zero marker line.
On the forum I found all sorts of solutions for coloring measurements, but unfortunately I can't get it to work.

Here is another post which asks a similar question, but hasn't been answered yet:
Color Line Chart by Segmented Colors in Master Mea... - Qlik Community - 1595241

Does anyone have an idea how to achieve this?
Please feel free to fiddle with the attached qvd and upload your adjustments.
Thanks in advance for your time and efforts!!

Kind regards,

Sebb.

 

Labels (1)
  • SaaS

1 Reply
SBDataspark
Creator
Creator
Author

Hi there,

An update on my progressions.
I managed to color the lines individually, but only if I set the second measure "Amount + Additional" as an alternative measure.

Sebb_0-1645173356384.png

Sebb_2-1645173941366.png

By setting the following expression in the "Colors and legend" setting:

=If(GetObjectMeasure()='Amount' and [Amount] < 0
, rgb(255, 0, 0)
, If(GetObjectMeasure()='Amount + Additional' and [Amount + Additional] < 0
, rgb(255, 0, 0)
, rgb(48, 122, 66)
)
)

Please have a look at the attached QVF.

When I drag the alternative measure back to the list of measures the expression doesn't color the individual lines.
So there must be some other way to make it work to have both measures in the same line chart, but individually colored...😉

Thanks again!

Kind regards,

Sebb