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.
Related
am trying to get Previous Sum(of someField) based on a variable value which is an Id.
This is not a table, Im doing a KPI
On Qlik you would do something like:
SUM({<Id={"$(=Max(vVariable),-1))"}>} someField)
But I can not achieve it on Tableau, off course is due to my lack of knowledge, unfortunatelly time is tinking at work and wanted to see if anyone has any input!
Thanks
Assuming you may use a sample input like the Superstore (using sales as metric), this could be what you're looking for:
In red you can see your "variable" which allows you to select a value and in blue you'll find the unique row for the previous value (Order ID sorted).
The first thing you need to to do is creating a parameter based on all the Order ID values:
Then things start to get a bit complicated if you're not familiar with LOD (Level of details) and the order of execution in Tableau, especially for filters.
Assuming that you can get some information on your own (otherwise, feel free to ask), the first thing you nee to to do is to "pre-calculate" the equivalent of a table having a rowe for each Order ID, in which you also have the previous Order ID value.
You can achive this combining Fixed (LOD) and Lookup function, creating this Calculated Field "Lookup Order ID":
LOOKUP( max({ FIXED [Order ID] : MAX([Order ID])}),1)
This is actually just a calculated field that you want to "fix" because you need the filter to act after you have made that previous calculus, and then you shift your data by 1 row backward.
Once you've done that, you just nee to create another calculated field in order to test your parametric value, and it could be something like this "check param":
[Lookup Order ID] = [Order ID param]
Moving this calculated field in the filter section and selecting just "true" values, you'll get that unique rows like in the initial image, showing the previous value (blue) related to the one you select in the parameter drop-down menu (red).
For example, I show two columns--CustNumber and CustName. In a filter, I would like to concatenate the two values something like this:
10100 My Customer
This would allow the user to enter either the customer number OR some of the customer's name in drop-down filter to filter by.
Thank you.
You would need to create a separate calculated field to use as the filter.
CustNumberName =
STR([CustNumber]) + ' ' + [CustName]
CustNumberName can then be used as a filter (presumably set to Wildcard Match) and the existing 2 columns can stay in the pane.
You can create a calculated field as G Hart states.
You can also create a combined field, by selecting multiple dimensions in the data pane and right clicking to Create->Combined Field. The combined field behaves very similar to a calculated field in most respects and you can easily change the delimiter or field order.
There are a few restrictions with combined fields. They can’t be used in most (or all?) calculations, nor to populate the list of possible values for a parameter. But they are easy and convenient otherwise.
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
I'm currently looking to count the number of instances a values shared across multiple dimensions. For example, say I have the following set of data:
And I want to return something like:
But ideally in the form of a bar graph. I want to keep the names associated with the data, so I can filter lets say by all "Bobs" or all "Hannahs".
Does anyone have any advice on how to do this in Tableau?
Here are a couple of ways you may be able to do this.
1) Create a calculated field for each food type. This is a bit cumbersome and you would need to add new ones for any new foods added. You calculations would look like this:
Hamburgers:
SUM(IF [Food1] = 'Hamburgers' OR [Food2] = 'Hamburgers' THEN 1 END)
Then you would make use of the Measure Names and Measure Values built-in fields.
2) You can normalize your data. If you are referencing a Excel or Text file, you can do this right in Tableau. Simply go to the Data Source tab, select the Food fields, and choose to Pivot them:
Goes to:
Now you can do:
Finally, both results support creating a bar chart:
I am attempting to write a sort field parameter for all of my 7 fields in CR10. I have followed the directions in the help section - Define sort order using parameter fields - and just tried 3 fields for the moment. I can't get either to work properly and I'm not sure if this is at all possible.
Here is what I have.
My report originally was grouped by 1 Payer ID and then 2 Claim Number. I removed those groups and moved my fields into the details section. Here are the fields:
`Claim#
Payer ID
Payer Name
Account#
Name
Billed Amt
Date`
I created a parameter called Sort Field, selected string and made sure my min and max were set to one. Placed the following into the prompting text:
`C = Claim
I = Payer ID
P = Payer Name
A = Account#
N = Name
B = Billed Amt
Date is Default`
I created a formula and called it Sort. I have tried this as stated above with all 7 fields and also only 3 fields - my main focus is all of the fields.
`If {?SortField} = "C"
Then totext({table.ClaimNumber},"########")
ElseIf {?SortField} = "I"
Then totext({table.ID_Payer},"########")
ElseIf {?SortField} = "P"
Then {table.PayerName}
ElseIf {?SortField} = "A"
Then totext({table.Account},"#######")
ElseIf {?SortField} = "N"
Then {table.Last_Name}
ElseIf {?SortField} = "B"
Then totext({table.ClaimGrossCharge},"#########.##")
Else totext({table.SubmittedDate},"")`
I then placed #Sort into the report header and suppressed in the section expert. I also included the following formula in the Record Selection:
`{table.SubmittedDate} >= {?Submitted Date From} and
{table.SubmittedDate} <= {?Submitted Date To} and
{#Sort} = {?SortField}`
Finally, I made sure that the #Sort formula was selected in the record sort expert.
I run the report and get nothing. I comment out {#Sort} = {?SortField} in the Record Selection and I get data. Although, the data is duplicating since it is not grouped as it was originally.
Can this be done? This option would be amazing for our clients and I have a feeling it can work but I believe I am missing something. Is my #Sort formula correct or does it need to be adjusted? I am attempting to make sure all of the fields are to text since I selected string in the parameter.
Any assistance would be greatly appreciated! Thank you for your time.
Its a bit lenghty question but will try to answer to the extent I understand.
I am assuming sort(From formula that you have written) you mean display only those values that client has selected and supress the rest and my answer will support this idea. If this is not you are looking for let me know will try to answer to the extent possible.
You shouldn't be using the {#Sort} = {?SortField} in record selection formula since this will be directly fired in database and as per your design this won't return any data as you parameter values doesn't match with the data in database.So remove this part from record selection.
Do place your sort formula in report header as it doesn't fetch full data in header and its of no use to supress.
As you place all fields in detail section you can use your created Sort formula in detail section in place of original fields which will do the job as per the user selection.
If you are getting the duplicate data then you need to check links to the tables or check the option Select Distinct Data in database tab which will remove duplicate data