Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jules_
Regular Visitor

Curve color depending on its position relative to another

I have 2 series of values: val1 and val2, and a column with dates. I want to show a graph with a date x-axis, and the 2 curves corresponding to val1 and val2. The 2nd curve should be red if below curve1 and green if above.

Jules__2-1688715799098.png

 

The first solution I came with is to create 2 columns corresponding to val2 in my database: val2_up would have the same value as val2 if above val1, and would be NULL if below val1. Similarly, val2_down would have the same value as val2 if below val1, and would be NULL if above val1.

Jules__3-1688716472879.png

Jules__4-1688716500912.png

 

The problem if I choose this solution is that I cannot add filters on family, category and type. Actually I could, but as PowerBI computes the total, If I choose to show for example only family1, it would compute 2 totals: the first with every values below val1 and the 2nd with every value above val1. Thus it would show 2 curves for val2, 

Jules__5-1688716572079.png

whereas I would only want 1:

Jules__6-1688716931065.png

If you have any other idea, I would appreciate if you could share it

 

1 ACCEPTED SOLUTION

Here is the solution I found : 

https://drive.google.com/file/d/14Du9Q5tZoDLIdWKZI9F1qL9m5RyI9GuV/view?usp=sharing 

I tried to add two columns in my database : val1_last and val2_last, and create 2 measures val2_over and val2_under in powerBI, which are basically the value of val2 if val2_last > val1_last and val2_last < val1_last, else null. With this solution, I would only get the last value of val2 respect the condition.

I entirely filled val1_last and val2_last columns with the last values, even if the date did not correspond to solve the issue.

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

I don't see curves, only straight lines.

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Correct, I want a line chart, not a curve graph. Sorry for the confusion.

 

Here is a link to google drive. I uploaded the sample data that I used to get the powerBI visualization above.

https://drive.google.com/file/d/1Wu9sA-RC1LSXBm5Yc6aJ4uNi2XJq21Di/view?usp=sharing 

 

I want these outcomes:

Jules__0-1689077228412.png

 

Jules__1-1689077284357.png

 

If the lines have different slope then they must intersect somewhere in Cartesian Space. That means you can end up in situations where you need to render a red and a green segment.

 

Anyway, you were close. See attached.

Thank you very much!

However it looks like I simplified my problem too much.

Here is what happens when I try this with a bigger sample:

https://drive.google.com/file/d/1Wu9sA-RC1LSXBm5Yc6aJ4uNi2XJq21Di/view?usp=sharing 

If one point is below Val1 and the following point is above, there is no line between the two, so I added an orange line behind the green and the red.

Sometimes I don't have value for val1 corresponding to the date of the val2 value, so I tried to change the condition of display: rather than comparing val1 and val2 at each date, I only want to compare them at the last date, when I have both val1 and val2.

Yet I haven't found a good solution, the LASTNONBLANK functions looks bad...

Thanks for your help!

You may want to go back into your thinking corner and work on providing sample data that fully covers all your scenarios. 

Here is the solution I found : 

https://drive.google.com/file/d/14Du9Q5tZoDLIdWKZI9F1qL9m5RyI9GuV/view?usp=sharing 

I tried to add two columns in my database : val1_last and val2_last, and create 2 measures val2_over and val2_under in powerBI, which are basically the value of val2 if val2_last > val1_last and val2_last < val1_last, else null. With this solution, I would only get the last value of val2 respect the condition.

I entirely filled val1_last and val2_last columns with the last values, even if the date did not correspond to solve the issue.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.