简体   繁体   中英

In Tableau how do you change y-axis to be calculated by custom function?

I am working with a 2 y-axis graph, one is generally between 40K and 60K, the other between 5K and 10K. What I would like to do is set the the 40K to be a number such as if the MIN = 42K, start at 40K and increment by 5K. If It is 38K, start at 35K. Similarly for the 2nd y-axis, do the same but based on 2K increments. When I set it to automatic I get basically straight lines or I say do not include 0 and i get huge drastic swings. I can set the starting and set the increment, but that means every day I would have to go in and verify that still works, for example 40K is a good start, but one that that may be too high or too low. (I suppose the fact it is 2 axis has nothing to do with it, but in case it does) The key is dynamically changing based on the result set.

If there is a better way to do this, I would love it. However, this got me close to what I wanted. First, I created 2 calculated fields, MIN and MAX using a windowed function on the data. They look something like this below. Note I did 2x the differences to give a window that is roughly 5x the total distance from min to max. Better math could give a better sizing.

Max_Ln=WINDOW_MAX(SUM([Profit]))+(WINDOW_MAX(SUM([Profit]))-WINDOW_MIN(SUM([Profit])))*2 Min_Ln= WINDOW_MIN(SUM([Profit]))-(WINDOW_MAX(SUM([Profit]))-WINDOW_MIN(SUM([Profit])))*2

I then added both to the Details pane and used this to add reference lines. I added the reference line with no title and no line. This will cause the automatic spacing to take them into account, but not show anything. From there I did the same on the 2nd y-axis and now everything looks good and will adjust dynamically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM