dynamic colour formatting in tableau - tableau-api

i have forecast bias values being displayed as percentages and i want to color those values based on certain thresholds like it should be RED if its value greater than 100% and less than -100% and green if between -99% to 99 % so i created a calculated field as
If [Forecast Bias] >= 100 THEN "Red"
elseif [Forecast Bias] <= -100 THEN "Red"
elseif [Forecast Bias] > -100 THEN "Green"
END
but i am getting some color field as Nul and wrong color on the values.I feel its taking actual values of forecast bias rather than percentage value for comparison.

Assuming you want to separate data rows based on their value for the [Forcecast Bias] field and treat rows separately depending on whether the value of [Forecast Bias] is within your range, then I suggest creating the following calculated field, called, say, "Bias_in_Range".
abs([Forecast Bias]) < 100
This defines a boolean valued dimension calculated field.
You can then place this field on the Color shelf to partition data according to that dimension.
To make the color legend more readable, you can create aliases for the dimension members, True and False in this case, to display labels like "In Range" and "Out of Range" to get readable color legend.
You could replace the hard coded 100 with a parameter, say "Bias Threshold", and show the parameter control to allow users to adjust the threshold dynamically.
abs([Forecast Bias]) < [Bias Threshold]
You will see null values for this field only for data rows that have a null value for [Forecast Bias]. If you don't like that, you have the choice of:
filtering out nulls,
fixing the source data to supply the missing field values, or
adjusting the definition of your calculated field to
treat the rows with null [Forcecast Bias] as either in range or out of range as you prefer, using a function like isNull() to test for null values
I can't speak to why you may see the wrong color without seeing more info about your data

Related

Filtering the View Without Filtering Underlying Data - TABLEAU

In the above image, I have added a lookup calculation to limit the number of values on the x-axis.
Formula for Lookup : lookup(min(([Weeks out ])),0)
{Weeks out} is the x axis
Currently the range selected is -36 to 0.
There are values present for >0 but because of the lookup, it doesn't show up.
I want to show the total running sum on the 0th axis(this should include all the values available after 0)
adding tabular format for better understanding

Two conditions on one formula field

I have a field, which takes values less than zero & greater than zero.
Also in that field, Values will be having leading zeros.
So I have used the following conditions like
Replace({Command. Field}, "0",".") and
If {Command. Field} < 0
then ((Int(tonumber({command. Field}))) *1000)
When I save the formula getting error like "A Boolean is required here"
Why I am getting this error?
Since this field has values less than zero & I want to automatically multiple that value with 1000 to get the desired output.
Is it possible to give both of the conditions in single formula?

Leave null celles without colors

I have Tableau table with few measures.
I want my pallette to take place in every cell with value and leave cells with null values(blank) without color.
The current situation is that null values are colored as 0 values. How can I distinct the nulls from the 0 values?
I tried to create calculated field but tableau doesn't allow to create calculated field on aggregations
Create a calculated field [COLORSCALE YOUR FIELD] where the null-values are replaced by something off-scale. e.g. if your number range is between 0.0 and 100.0 you could use:
IIF(ISNULL([YOUR FIELD]),-100,[YOUR FIELD]*X)
Where X is a scaling factor. Adjust the scaling factor and the "Start"/"End" options in the "Color" Menue to suit your purpose.
Another option based on mzunhammer's suggestion would be to use the min() function instead of assigning a hard coded value to replace the nulls, and may allow you to avoid the use of the scaling factor.
iif(isnull([Your Field]), min([Your Field])-y, [Your Field])
that way the null is always going to be y less than the lowest value even if the lowest values are changing as the dataset updates.

Code to compare the number of "false" to total number of cases

I am trying to create a chart in tableau which will show me the comparison in weeks, i.e. the comparison between the trend from week 1 to week 5.
In simple terms it should be like:
If Verdict = "Not Reversing" THEN count the total number of Verdicts
Else do not count
If IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
Error message shows cannot mix aggregate and non aggregate functions
Assuming your data source has exactly one data row per verdict ... (Always be clear about what one row in your data source represents.)
You could define a calculated field called Number of Non Reversing Verdicts defined as INT([Verdict] = "Non Reversing") That field will have the value 1 for Non Reversing verdicts and 0 otherwise. The INT() function converts its arguments into an integer, and treats TRUE as 1 and FALSE as 0.
You can then plot SUM([Number of Non Reversing Verdicts]) as desired, along with SUM([Number of Records]) to see the total number of verdicts -- or even compute the ratio of the two formatted as a percentage.
For extra credit, you could rename the predefined field [Number of Records] to [Number of Verdicts] for this data source if that helps make it more clear. (BTW, look at the definition of [Number of Records] and make sure you understand why that works)

mysqli, change all rows by increasing by a number, but not over a certain value

"UPDATE score SET
points = red_chips WHERE red_chips > current_turn"
I want to have points be equal to several different chip colours combined, but the MAXIMUM any individual chip colour can give you points must be limited by the current_turn, if the chip colour is higher it should default to only adding the current_turn.
"UPDATE score SET
points = red_chips + blue_chips + green_chips + yellow_chips + white_chips"
^ this but with EACH colour individually limited by the current_turn as a maximum amount.
I am looking for a way to do this without having to make a new query for each chip colour.
I think what you're looking for is LEAST(current_turn, [xyz]_chips). This will use the chip value if it is less than current_turn but the value of current_turn if the chip value is greater than that.
That is, if you want points to be equal to the sum of all of chip values with each limited to the value of current_turn, you want something like this:
UPDATE score SET points = LEAST(current_turn, red_chips) + LEAST(current_turn, blue_chips) + LEAST(current_turn, green_chips) + LEAST(current_turn, yellow_chips) + LEAST(current_turn, white_chips)
That's assuming that the [xyz]_chips values contain the actual net value (correcting for the value of each color). Depending on what current_turn represents relative to the chip values/colors you may want to multiple by the chips relative values. But if what you're looking for a count of the chips, not necessarily accounting for color, or if the [xyz]_chips column contains a color-adjusted value, then you should be fine.
Also, to clarify a bit about my edit, MIN is a aggregate function that acts on columns finding the minimum value from the rows. LEAST is takes two or more arguments and returns the one with the smallest value (or NULL if any of them are NULL), so it acts on the values of each individual row.