Tableau - Find Null Values across Specific Dimension Values - tableau-api

Working in Tableau - My data set looks like this:
Filename Run Score
File1 Run1 80
File1 Run2 Null
File1 Run3 Null
File1 Run4 60
File2 Run1 70
I need to be able to filter the file data based on Nulls being in certain runs. My current plan is a calculated field being used as either a parameter or filter (or both):
IF $score_for{$file}{'Run2'} == Null && $score_for{$file}{'Run3'} == Null
THEN $file{'calc value'} = 1 (or 'null values in runs I care about')
Then I can filter all 1's out of the charts and look at the files that did work for runs 2 & 3.
I have a feeling I can do this using INCLUDE, but for the life of me I can't figure out how that works. I've watched their training video three times.

It looks like your end goal is to identify files that satisfy a condition - in this case, files with non-null values for the runs of interest. This is a good case for using Tableau sets.
There are alot of ways to think of sets: a named filter, a Boolean function defined for each data row, a mathematical set defined for members of some discrete field. I'd recommend something along the lines of:
Define the set of Runs of Interest -- right click on the Run field in the data pane in the left sidebar. Choose Create Set. Call it "Runs of Interest" and manually select the Runs that you want to belong to that set: Run2 and Run3 in your example.
Define the set of Files that Worked -- right click on the Files field, Create a Set. Name it "Working Files", and then instead of manually selecting set members, choose the Use All radio Botton an the TOP of the set dialog, and then choose the Condition tab to define the condition that distinguishes working files from the non-working files.
Enter a condition as a formula such as: MIN(NOT ISNULL([Score])) which will be satisfied for Files where EVERY data row has a non-null score. If instead you want files to belong to the set if ANY data row has a non-null score, then use MAX() instead of MIN().
Now that you have your Working Files set, place it on the filter shelf to restrict the viz to only working files. You can also use sets on the row/col shelves or in calculated fields. You can edit the Runs of Interest set as needed, and the Working File set will adjust

Related

How to extract just the IN count of a Tableau set

How can I extract the IN count portion of a Tableau set? I can see the IN/OUT counts when I drop the set into Text but can't figure out how to get at the IN value by itself.
Ultimately, I want to create a Pie Chart of three sets with just the IN counts as the measures.
I am using Tableau Public if that is a factor.
You have to be a little careful about specifying what you wish to count.
One way to think of a set is as a Boolean function that gives a value to each data record denoting whether that record is associated with the set.
Another way to think of a set is as a mathematical set whose members are a subset of the values for some discrete field. (Or Tuple of fields)
The difference between the two views is really just a mindset, whether you consider the set as a Boolean function whose domain is a data row in the data source, or whose domain is the field on which the set definition is based.
Say you are looking at Tableau’s Superstore data set where each data record is a line item for a product attached to an order.
If your set is based on the field Region, say its called [My Favorite Regions] and currently contains {“East”, “Central”} do you want your count to be 2 (i.e. the number of regions in the set) ? Or do you want your count to be in the tens of thousands (i.e the number of line items on orders from the regions in the set)? Or something in between, maybe the number of distinct orders (i.e. order ids) within the selected regions...
If you want to count data rows that are associated with the set, you can simply filter by the set and calculate SUM([Number of Records[). If you want to count the regions in the set even though the level of detail of the data is at the order line item level,then you’ll have to use either a COUNTD to count the distinct regions, or some approach to specify what it is you want Tableau to count.
For example, put your set on the filter shelf, and show COUNTD(Region) which could be slow for very large data sets. To get the same effect without an explicit filter, you can define a LOD calculation such as:
{ COUNTD(if [My Favorite Regions] then [Region] end) }
Or you could use a table calc with the SIZE() function to do the calculation in the Tableau client instead of by the data source.
Not sure what your data looks like but you could set a certain condition when creating a set or split the IN/OUT into two different sets.
Here's a link to sets in Tableau.
You can do this with an if statement
IF [set] = TRUE THEN 1 ELSE 0 END
Then I suppose you could sum this calculated field
The most common usage is when you have a lot of categories and want to create an 'Other' category based on the categories that aren't in a set, if the set is a "Top N Set"
To do this:
IF [set] = TRUE THEN [dimension] ELSE 'Others' END

Perform analysis on last three values of a FileMaker dataset

My end goal is to have a box change color when the last 3 records input into a field (based on the time of input) in FileMaker achieve a certain criteria (ex. variance < 2). I would like to know how to make this happen, or how a calculation/script can be written to only look at the last 3 records.
There are several ways you could approach this. A simple one would be to use a script to:
Show all records in the given table;
Unsort them (assuming they were entered in chronological order; otherwise sort them by creation timestamp);
Omit all records except the last three;
Get the value of a summary field defined as Standard Deviation of your value field;
Set a global variable/field to the square of the returned value.
Then use the global variable/field to conditionally format your "box".
If you don't want to use a script, you will have to define a relationship in order to get the last three values in the table, regardless of the current found set and/or sort order. Or you may use the ExecuteSQL() function for this.

Tableau: custom grouping by string

I’ve got data that looks like this:
Drug name:
Methylphenidate
Methylphenidate
Acetaminophen
Ritalin
Ritalin
Tylenol
Tylenol
I want tableau to treat “Ritalin” as “Methylphenidate”, and “Tylenol” as “Acetaminophen” for all purposes. I'm ideally hoping someone will point me to a menu or calculated field script where I can write out a long list of string substitutions. The full data set will have about 50 such changes to make.
For this example, I’m trying to count the number of times Methylphenidate/Ritalin is prescribed, and the number of times Acetaminophen/Tylenol is prescribed. Here, I want the output to be Ritalin = 4, and Tylenol = 3.
The only solution I can think of is to go into the data source, duplicate the "Drug name" column and run a "find and replace", but that's inelegant and would need to be repeated when data is added.
Thanks for the help.
If you are mapping multiple values to a single value (rolling them up), then use a Tableau group. The easiest way is to:
put Drug Name on the rows shelf
multi-select (shift-select) values that you want to combine
click the paperclip icon on the toolbar to group them together
right click on the resulting combined name and set a shorter alias of your choosing
The effect is to create a new group field based on the original Drug Name field that acts like the calculated field #Aron defined.
If instead you want to map each individual value to its own distinct label (say to display a meaningful name instead of a short cryptic code from the database), then you can create aliases instead of a group.
No problem. You can do this with a simple calculated field. Create a new calculated field and follow this logic
if [NDC Description] = 'Abilify' then 'user1791903'
elseif [NDC Description] = 'Actos' then 'user1791903'
elseif [NDC Description] = 'Actonel' then 'user1791903'
elseif [NDC Description] = 'Acyclovir' then 'Group2'
elseif [NDC Description] = 'Aciphex' then 'Group2'
else 'Unknown'
end
Basically, this will evaluate each record and depending on whether NDC Description is X or Y, it will output "user1791903" or "Group2" or "Unknown" if the record doesn't match any of the text you entered. Then, you can drag this calculated field to the shelf and it will display using this grouping, and you can then add aggregate functions and whatever else you need.
All these responses were very useful. The solution I ended up using:
I created a separate spreadsheet with a list of drug names and their generics. Then I ran a table join, adding it to the large dataset. This approach was valuable as it allowed me to easily add and edit drug definitions later on, and even add more metadata.
Thanks to everyone.

Show calculated measure in row?

I'm using Tableau Desktop 9.0 on OSX. I have data (loaded from a local CSV file) that looks like this:
code,org,items
0212000AA,142,10
0212000AA,143,15
0313000AA,142,90
0314000AA,143,85
I want a chart that shows the number of items beginning with 0212 as a percentage of all items, for each organisation. (I mean as a percentage of the organisation's items - for example, in the above, I would like to show 0.1 (10/(10+90)) for organisation 142.)
I have been able to get part way there, by adding org to Columns, and SUM(items) to Rows. Then by adding a Wildcard filter on code, for starts with 0212.
This shows me the number of items starting with 0212, by organisation.
But what I don't know how to do is show this divided by the value of all items for the organisation.
Is this possible in Tableau, or do I need to pre-calculate it before loading my data source?
One way is to define a calculated field called matches_code_prefix as:
left(code, 4) = "0212"
You can also define a parameter called, say, code_prefix to avoid hard coding the prefix string:
left(code, 4) = code_prefix
And then show the parameter control for code_prefix to allow the user to interact with it.
If you use this new field as a dimension to separate SUM(items) according to those that match the prefix and those that don't, you can then use a quick table calculation to get the percent of total.
For example, you can place org on the Rows shelf and matches_code_prefix on the Columns shelf, and SUM(items) on the Text shelf to make a table. Then under the analysis menu, turn on grand totals for both rows and columns to see the behavior. Next, right click on SUM(items) and choose Quick Table Calc->Percent of Total. Tableau will display the percents of total in the table.
If you want the percent of total defined differently than the default, then right click on the measure again and set Compute Using to a different value such as matches_code_prefix in your case. It's usually better to set compute using to a specific field.
If you only want to display the value for the matching case, select the column header you don't want to see and choose hide. You can also turn off the grand totals from the analysis menu when you are done.
When you are confident in the values in your table, you can turn it into a bar chart for example by moving matches_code_prefix to the detail shelf and the measure to the Columns shelf.
--
The above is the drag and drop approach. If you prefer to hard code everything in a single calculated field that is calculated on the database side, you could instead define a calculation such as:
zn(sum(if matches_code_prefix then items end)) / sum(items)
Then set the default number format for that field to display as a percentage

FileMaker: Is there a way to build an export order in a script?

Question: Is there a way to build an export order while performing a script? I would prefer a FileMaker-native or FileMaker-called AppleScript solution, if one is possible.
Project: The project is a reporting tool which summarizes sales information (units, price, cost) by user-selectable criteria such as: week, quarter, year, location, product, supplier, etc. I would like a way to specify, at runtime, an export based on the user-selected criteria.
Example: If a user selected units sold summarized by supplier per quarter I would like to be able to have the script select:
Group by:
quarter
supplier
Export Order
quarter
units summary by quarter
supplier
units summary by supplier
There are obviously many permutations, so setting up an export for each individual export for each set of options is infeasible.
If the target format is text-based (i.e. tab- or comma-separated), then I'd export to XML and write a XSLT to summarize it as necessary. To pass parameters to the XSLT I normally export a small XML file to the same folder.
A solution I can think of is to export calculations rather than the original fields. With the example you give, assume that the user can export up to two fields. You create two calculation fields and two text fields. The text fields store the name of the field to export and the calculation fields use Evaluate (or GetField) to get the contents of the fields. It gets complicated if you're also exporting date and time fields, but it's still workable. If you need to include the field names in the export, you create an extra record and work your calculations for that record to contain the names of the fields the user has selected.
Not trivial, but still possible.
Building on Mikhail's and Chuck's suggestions, I think the best method for this particular project is going to be to build the contents of a .csv in a global field and then Export Field Contents. The basic outline of what I'm doing:
Go to the first record
Loop
WriteTheRows (see below), comma delimited, to a global field
Set $thisGroup to the count of records summarized by this summary field
Exit Loop If Get (CurrentRecord) + $thisGroup >= Get (FoundCount)
Go to record [Get (CurrentRecord) + $thisGroup]
End Loop
Export Field Contents [global field]
WriteTheRows is a custom function that does the following:
The output I'm trying to write can be sorted by up to 7 different criteria at the same time (for example: I could summarize supplier sales by quarter or I could summarize quarter sales by supplier)
Compare the highest level sort field's value to the last value we found for the highest level sort field.
If they're different WriteALine to the global field for this sort field, the next sort field, all sort fields down to the lowest level.
If they're the same, compare the (highest level sort field - 1) to the stored value for the (highest level sort field - 1)
If they're the same, WriteALine to the global field for the (highest level sort field - 1) on down to the lowest level sort field
... repeat until we're down to the lowest sort field
WriteALine is another custom function which adds the appropriate labels, commas and values using the GetSummary ( revenueSummary ; Evaluate ( "summaryField" & summaryFieldNumber ) as Chuck suggests in his answer.