Calculated Fields in Tableau - calculated-field

Suppose "ABC" is my dimension and it has categories "a", "b", and "c". In tableau, I have the following calculated field:
IF [ABC] = "a" THEN 1 ELSEIF [ABC]= "b" THEN 2 ELSE 3 END
This calculated field shows up in the measures section. However, I would like it to show up in the dimensions section so that I can sort by these numbers. In other words, I am trying to numerate the original data while still being able to use it the same way. Does anyone know how to make the calculated field show up in dimensions? Thanks!

You can just drag the calculated field from measures to dimensions panel.
Please consider that if you made this dimension only for sorting you can use a manual sorting option as described in this guide.

Related

Is it possible to add 2 rows of header to a Microstrategy Dossier?

in Microstrategy Dossier, is it possible to create 2 rows of header, such that the first row is the grouping information and spans to number of columns to identify as a group? for example : group "Inbound costs" should span to "Dep1 | Dep2 | Dep3" and "Outbound costs should span to " Transportation | Energy | Warehouse " ?
It will be a bit different if you are grouping attributes or metrics, but I think it should work either way.
If grouping attributes, that is pretty straightforward. Put the attribute in the columns, then right-click and select "Create Groups...". From there, put the elements into one group that is labeled "Inbound Costs" and make another that is labeled "Outbound Costs". Once you have the group made, then just drag in the original attribute under it. Might need to play with formatting to make sure that the repetitive cells are merged and centered, but that would group the attributes across the columns.
If grouping metrics, it is a bit more involved. First, do "Change Visualization" on your grid and set it to "Compound Grid". This will allow you set the different sets of columns that behave differently.
Then, put the "Inbound Costs" into one column set and the "Outbound Costs" into another column set. This groups them, but doesn't label them quite yet.
To label them, right-click on any attribute in the dataset panel and select "Create attribute...". Name the attribute whatever you'd like and have the definition be "Inbound Costs" and set the data type to "String". Drag this new attribute above the metrics in the first column group (making sure it is still in the group). Repeat the same for "Outbound Costs" and then work on formatting to merge the repetitive labels and center.
Here is a quick screenshot of how I was able to make it look using some fake data, if that is what you were indeed trying to do.

Redaction in Tableau

I am currently in the process of building some Tableau workbooks where we will need to redact visualizations or text tables if the results fall below a certain threshold (e.g. only ten data points are returned after filters are applied). Does anyone know how to create calculated fields or know of other methods to redact in Tableau?
You can create a threshold filter that compares the number of filtered responses to a threshold value set in a parameter.
First, create a parameter with integer data type and set it to the desired threshold. In this example, I called it Count Threshold.
Then create a calculated field for the filter with an equation like the following:
{FIXED: COUNTD([Respondent ID]) >= [Count Threshold]}
(I did this for survey results where we needed to hide results if the filtered number of respondents was fewer than 10.)
For the threshold filter to be applied after your other filters, choose "Add to Context" for your other filters.
I found a partial solution on the Tableau community forum/knowledgebase about redaction that might work for other implementations.
The basic idea is to create two different calculated fields, one which displays a integer value and the other that displays a string value. That way, when both are concatenated in the display you get the desired output without breaking any of the calculated field rules.
So create a calculated field that has a formula like:
IF sum([Datafield_to_Redact]) < 10 THEN "*" ELSE str(sum([Datafield_to_Redact])) END
And another that has a calculated field that has a formula like:
IF sum([Datafield_to_Redact]) < 10 THEN null ELSE sum([Datafield_to_Redact]) END
In the post the attached workbook and screenshot show how the two values are concatenated in the Text mark.
Workbook screen capture

Spotfire calculated column based on filter

I want to create a calculated column that is equal to the percent of the total of the previous column, but only for the rows that are selected.
For example, the two columns below show rows where I've filtered for only the rows of interest. The sum is accurate, but I want the percent of the total to be only out of sum of the currently selected rows rather than the absolute total (which is how it's currently being calculated). I want the percent of the total to dynamically change depending on what is filtered in the data table. Is this possible?
Image of my 2 columns:
I know spotfire somehow calculates this becuase when I insert a bar graph using % of Total(SumofComponents) the ratio is only out of the current total.
Image of my bar chart:
much like in programming, Spotfire has a rough concept of scope. and unfortunately, calculated columns are above filters in terms of scope; they have no concept of what is and is not filtered.
visualizations themselves, however, do*!
what you can do in this case is to put your expression on the Y axis (it looks like you've done this), and it will respect your selected filters*.
*caveats: there are a few ways that filtering can be negated on a given visualization:
Properties>>Appearance>>Show shadows indicating the unfiltered data. this option shows a grey bar that represents the data hidden by whatever filter selection was made
Properties>>Data>>Limit data using filterings. these options allow the viz to use separate filtering sets ("Filter Schemes" as they're called in Spotfire) or none at all (to ignore filters completely)
Properties>>Subsets. by default there are three subsets: "All Data" which ignores filters, "Not in current filtering" which inverts the filter selection (e.g., if you filter a boolean column to show only TRUE, this chart would show only FALSE), and "Current filtering" which is the default behavior. you can check the online help for additional subsets that you can add.

SSRS Matrix Report : Colors condition

I have a matrix table created with Rows as Days ,Columns as Months and quantity of rainfall as the data field(got all this information from same table 'Rainfall'). I have taken this data from a dataset containing multiple tables in SQL. All of this information displays properly.
Now I have many tables with date field in my dataset in tables other than 'Rainfall'.
In the data field of the matix I need to be able to add my own colors using a Switch case.
The Condition I need is "if a certain date from one table matches the date in my report then i want xxx colour."
eg: there is a table called fertilization which has 3 dates. Now if these 3 dates also exists in my matrix then that block should be colored blue.
Can anyone help me. Thanks!
You can also manage it from sql side while retrieving data from Rainfall table.
You can do this using by right clicking the field that you want the dynamic color on and selecting properties. Select Border and then where it says color hit, click the Fx button. Here you can write a custom expression that will change the background color based upon your code.

I am trying to create a calculated field from multiples columns by each row in Tableau

I have 5 columns.
SAMPLE HIGH MEDIUM LOW TOTAL
A________________5______________4______________7_____16
B________________5______________4______________7_____16
C________________5______________4______________7_____16
D________________5______________4______________7_____16
I want to be able to calculate for each sample the percentage of High Medium Low.
High/ total = new value
medium/total = new value
low/total=new value
How do I do this in Tableau?
You can read here for more details, but the general way is to right click on the Dimensions or Measures small window and then click on Create Calculated Field.
When the windows opens, in your case, you'll want to create a new name for the 'New Value', and then for the Formula section you should put:
[HIGH]/[TOTAL]
Just make sure that these are recognized as floats or integers (and not strings). If you select the variables in the Fields section, you are more likely to get exactly what you want. Also, there is a preview on the right of the data type.