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
SergioJG
Frequent Visitor

Graph positive numbers as negative

Dear colleagues,

I have the next challenge; I am ploting depths. Depth (not height) is a positive value. The largest, the deeper.

I can plot that vs. time on a very simple line chart. But the line climbs up.

First I tried was to create the simplest ever "new column": -[DEPTH]

It works, and the graph now goes down. However the legend is also negative, which I dont like.

Spotfire has an option to graph inversely. But I cant find nothing like that in Power BI.

¿Can any one help, or figure out any way to show the legend without the 'minus'?

Thanks in advance!!

Sergio

1 ACCEPTED SOLUTION

I don't think you can do this with the default visuals. Besides finding a custom visual in the store, here is how to do it with R scripting:

 

  1. First, follow this article if you don't have R scripting set up for PBI yet: https://docs.microsoft.com/en-us/power-bi/desktop-r-visuals
  2. Once set up, you should have R scripting as a visual option, click it and drag in your TIME and DEPTH columns (make sure it's TIME then DEPTH as that affects structure of what you plot with R), like so:
    image.png
  3. Then, in R script editor, enter:
    plot(dataset , ylim = rev(range(dataset["DEPTH"])) ,lwd=4 , type="l" , bty="n" , col=rgb(0.2,0.4,0.6,0.8) ,xaxt = "n")
    axis(1,at = unlist(dataset["TIME"]))
    (credit to here for getting me started as I'm an R novice: https://www.r-graph-gallery.com/77-turn-y-axis-upside-down/)
  4. Hit Run script button and you're all set:
    image.png

View solution in original post

8 REPLIES 8
v-yuta-msft
Community Support
Community Support

Hi SergioJG,

 

Could you share some sample data and clarify more details about your requirement?

 

Regards,

Jimmy Tao

Imagin a set of data as follows:

 

Captura.JPG

 

 

On a standard line graph, that will be line starting on 0,0 going to the right and climbing up:

Captura1.JPG

However, I am trying to plot depth, and a positive depth value should be below cero.

First idea was a 'new meassure' turning DEPTH column into a negative value, so the excel input can still be positive:

DEPTH 2 = -[DEPTH]

Captura2.JPG

But still the legend is negative.

How can I plot my positive value in this second way, or hide the "minus" on the Y axis if I just change the sign with a calculated column?

Thanks!!

Hello SergioJG,
I am a bit confused. Can you elaborate which part of the visual you call a legend? Is that the Y axis?

Yes sorry, Y axis. I need those numbers ro be positive, or not showing the "minus". Same as they are on the table. Or else, keep them positive, but plot them below the X axis, as shown on second graph, as those mean "deapth", which is positive going down.
Thanks for any suggestion!!

I don't think you can do this with the default visuals. Besides finding a custom visual in the store, here is how to do it with R scripting:

 

  1. First, follow this article if you don't have R scripting set up for PBI yet: https://docs.microsoft.com/en-us/power-bi/desktop-r-visuals
  2. Once set up, you should have R scripting as a visual option, click it and drag in your TIME and DEPTH columns (make sure it's TIME then DEPTH as that affects structure of what you plot with R), like so:
    image.png
  3. Then, in R script editor, enter:
    plot(dataset , ylim = rev(range(dataset["DEPTH"])) ,lwd=4 , type="l" , bty="n" , col=rgb(0.2,0.4,0.6,0.8) ,xaxt = "n")
    axis(1,at = unlist(dataset["TIME"]))
    (credit to here for getting me started as I'm an R novice: https://www.r-graph-gallery.com/77-turn-y-axis-upside-down/)
  4. Hit Run script button and you're all set:
    image.png

Thanks MarkLaf,

I will try that in the upcoming days and let you know. On your example looks working exactly as I need!

Thank you very much for your time and support.

Sergio.

Solved!

Thank you very much. Working nicely!!

_donev
Regular Visitor

Legend and values are different properties of a visual so generally you can use the positive number column for Legend and the negative for Values. But this is just the answer without knowing your case. Probably if you can share some sample of your case? Like a screenshot of the visual?

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.

Top Solution Authors