Tableau Calculated Field to Display Specific Rows - tableau-api

I'm trying to find a way to display only certain rows of my data based off a very specific criteria. I will try to explain it the best way I can. Let's start with a screenshot here:
Picture of part of the Tableau sheet as-is
What I'm trying to do is create a way to display only the values of "Order: Sales Order #" that have a value filled in for "Item: Connected Product Category". As you see on the screenshot, order number 15589543 has one Connected Product Category that displays "Connectable".
Since this order number does not only have null field for the Connect Product Category, I would like ALL of the rows (even the blank ones) be displayed for order # 15589543. If an order # has NO rows that have "connectable" displayed in them (orders 10305573, 15573299, 15699578, etc.) I would like these orders to be filtered out.
This is a screenshot of just a small part of the data. Basically, if an order has a "connectable" field in it, I need all of the rows for that order # to be displayed.
I tried to do logic such as IF [Item: Connected Product Category] = "Connectable" THEN [Order: Sales Order #] ELSE NULL END but this only displays the rows that literally contain "connectable" in them, not all of the rows for that order number.
Any assistance would be greatly appreciated. After extensive research I'm not sure if this is even possible. Thanks

It is simple. Create a calculated field desired filter as
{FIXED [Order: Sales Order #] : SUM(
IF [Item: Connected Product Category] = 'Connectable' THEN 1 ELSE 0 END
)} > 0
This calculated field will evalaute as TRUE/FALSE and setting filter on this field for TRUE will filter records as desired.
Try this. Good luck

Related

Tableau KPI prev value depending on variable

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).

How to filter one source by clicking and filtering a bar chart from another source in Tableau?

I used an Apriori algorithm to view the frequent relationships in the dataset and I want to do a dashboard to better visualize this data but I don't know how to do this filter.
This is the bar chart that I created to show the support (amount of times something happend) and the confidence (probability of B happening given A) of these associations:
Apriori Chart
Next to it on the dashboard, I'll have a table with the full dataset used in this Apriori analysis where I have more information such as ID, Income, Hours Worked, etc:
Table from different data source
How can I create this relationship? The two data sources don't have a column in common that I can use for that.
I would need some way to:
Split the values in the antecedents columns by comma and filter only those columns with value equal to 1 in the other dataset
**Dataset A**
'Age Range <=30, Joblevel 1, Maritalstatus Single'
->
'Age Range <=30'
'Joblevel 1'
'Maritalstatus Single'
**Dataset B**
'Age Range <=30' == 1
'Joblevel 1' == 1
'Maritalstatus Single' == 1
Clicking this would filter the table next to it
Is there any way I can do this in Tableau?
You can download the tbwx i used in this example here https://community.tableau.com/servlet/JiveServlet/download/1083124-384949/Apriori.twbx
Thanks in advance for the help!
I am not able to check your twbx on the machine I'm using but I think you should be able to do this. The fields in the 2 data sources need to match so manipulate the data sources the make this happen.
For data source 1 there's a function SPLIT which will mean you are able to split the comma separated string to 3 fields.
Putting those 3 fields to the Detail shelf of your bar chart (or even Rows and hiding the header) will mean you can use them in an action filter.
Your second data source is a cross tab - post pivot. You should be able to pivot this data source. Highlight the measures and pivot them. This will give you the field Pivot Field Names and Pivot Field Values.
You only want to keep those with a value of 1 so create a calculated field
[Lookup1]: IF [Pivot Field Values] = 1 THEN [Pivot Field Names] END
Duplicate this field twice so you have Lookup1, Lookup2 and Lookup 3.
Then you should be able to action filter the table.
In the action filter set it up so SplitField1 = Lookup1, SplitField2 = Lookup2, etc.
Fingers crossed this works, I haven't been able to test so I am pulling it out of my head.

Count of group dimensions item in Tableau

I'm fairly new to tableau and I'm having the following issue. Below is a sample of the data I'm using.
Customer No | Item
___________________
1 A
1 B
2 A
3 A
4 A
4 B
5 B
6 A
I'm trying to get a count of how many customers bought Item A and B. So far I tried doing a separate group by combining A and B but I get the total result of 8. I also tried doing a calculation and I'm getting the same result of 8. Can someone please point me to the right direction on how to get this result. Thanks!
This is the result I'm trying to get:
Item| Count
A 5
B 3
A and B 2
I recreated your exact dataset and pasted it into Tableau so you could see a couple of examples.
Here's how you can see the number of customers who purchased an individual item, plus the number of customers who purchased both items.
Your calculation will be:
IF { FIXED [Customer No]: COUNTD([Item]) } = 1 THEN
[Item]
ELSE
'Both A and B'
END
And you'll need to set your view up to look like this:
Below are ways you can see when both items were purchased.
Boolean OR
The calculation you'll want to use is:
ATTR([ITEM]) = 'A' OR ATTR([ITEM]) = 'B'
And you'll want to set up your view to look like this:
A, B or Both
If you would like a bit more specificity in your result, you might try:
IF ATTR([Item]) = 'A' THEN
'A'
ELSEIF ATTR([Item]) = 'B' THEN
'B'
ELSE
'BOTH'
END
Replacing the previous calculation with the new looks like this:
More than 1 item
If the specific items purchased don't matter, you could use this logic.
COUNTD([Item]) > 1
Replacing the previous calculation with this one would look like:
More than 1 Item using a window function (probably overkill)
The calculation you'll need to use is:
WINDOW_COUNT(COUNTD([Item]))
Because this is a Window function, we'll need to specify how it's calculated across our dimensions. To do this click the down arrow on the right-hand side of the pill and select Edit Table Calculation...
You'll then need to set these settings:
I'll add the calculation we created in the first example ([A and B]) to the filter shelf and select True. That should give you something that looks like:
More than 1 item using a Level of Detail expression
The calculation for this example is:
{ EXCLUDE [Item]: COUNTD([Item]) }
You'll view should look like:
As you can see Tableau is quite flexible. Hope these examples were helpful!
You might want to use Tableau’s set feature to approach problems like this.
For example, right click on the field [Customer No] in the data pane (i.e. left sidebar) and choose the “Create Set” command. Click “Use All” at the top of the set panel and then click the Condition tab. Define the set using the condition MAX([Item] = “A”). Name the set “Customers who bought A”.
Similarly, create a set of customers who bought item B. You can then select both sets in the data pane, and create a combined set to be the intersection, that is, customers who bought both an item A and an item B.
You can think of a set as either a mathematical set of the members of a field that belong to the set (i.e. a set of customer ids) or as Boolean function defined for each data record in the data source indicating whether that data record is associated with the set (i.e. a Boolean function that operates on transactions to say whether the associated customer ID is in the set. A key to keep in mind for the condition formulas used here is that the condition is an aggregate formula, operating on a block of data records for a customer ID to determine whether the customer ID is in the set.
Once you have defined your sets of interest, you can use them in many ways - in calculated fields, as filters, as dimensions on shelves in a visualization, in set actions, to combine with other sets ...
To define a measure that counts the customers in a set, create a calculated field such as “[Num A Customers]” as COUNTD(if [Customers who bought A] then [Customer ID] end) Do the same for whatever other sets you are interested in. Then you can use those measures (probably with Measure Names and Measure Values) to make your viz.

Using COUNT in Tableau to count observations by group

Thanks in advance for any advice you can offer! I'm building a Tableau dashboard to explore housing affordability and school quality in different neighborhoods in my area. A user will select their occupation and see a graph of neighborhoods plotted based on school quality and housing affordability. To explore housing affordability, I'm using county level assessor data with the valuation of every property matched to neighborhoods.
The goal is to display the percentage of homes in an area that are affordable given the median occupational wages for the job a user selected. Right now, I'm trying to use a calculated field with COUNT([Parcels]<[Occupation])/COUNT([Parcels]), but I need to find a way to count the number of properties in each specific neighborhood below the cut off value.
Does anyone know of a way to count elements of a particular group in this way in Tableau?
I'm on a Mac, using Tableau Desktop, and doing the back end analysis work in R. Thank you!
You seem to misunderstand what the function COUNT() does. You are certainly not alone. Count() behaves in Tableau almost identically to how it does with SQL.
Count([some field]) returns the number of data rows where the value for [some field] is not null. It does not not return the number of rows where [some field] evaluates to true, or a positive number, or anything else.
If [some field] always has a non-null value, then Count([some field]) is the same as SUM([Number of Records]). If [some field] is always null, then Count([some field]) is zero. Count() is not like Excel's CountIf function.
If you want to count data rows that meet a condition, you could try COUNT(if [condition] then 1 end) Since the missing ELSE case defaults to null values, that expression will count rows where [condition] is true.
So one way to get the percentage of affordable homes is count(if [affordable] then 1 end) / count(1) assumes each Data row represents a home. Then format your field to display as a percentage. Another option is to learn to use quick table calcs
If you want to display the number of rows in a given visualized table you could also use SIZE()
Source, official docs:
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#size

Using both counts and averages in tableau

I've got some data that I'd like to display both the averages and the count for.
For instance, there are 50 People taking a survey. Their names are saved in a Dimension "Raters". They are taste testing several products. These products are saved in a Dimension "Products"
They answer 4 questions. Taste, Texture, Appearance, Uniqueness, all saved in Dimension "Question"
The actual ratings are saved in "Ratings". This is a measure.
I can very easily make a table with Raters on the Rows, Question on the Columns, AVG(Ratings) in the text.
This shows me the average score for each question the rater answered.
It looks like this:
Rater-----Taste-----Texture-----Appearance-----Uniqueness
Joe---------2.2---------4.3--------------3.7-----------------2.4
Bob--------3.0----------1.2-------------3.4-----------------4.4
Sally-------4.5----------3.3-------------4.5-----------------3.2
Jessica---5.0----------3.0-------------2.0-----------------1.0
So far, so good.
Jessica's results look suspiciously integerish. When I look at the background data, I see that she only answered for 1 product.
I'd like to be able to add a column to the right of uniqueness which is the count of all product responses for that person.
I've played with this quite a bit, and I'm not sure that it is possible. Maybe with LOD?
I'd also like to filter the table, so that only "tough" raters are shown. Criteria for this is: Their average response for at least two criteria should be below 3.0. That would include Joe and Jessica.
When I try to do counts based on averages, I run into the "cannot aggregate an aggregate rule".
Is there a way around this? It would be trivial to do in excel with another column, a countif, and a filter.
Thanks,
Chris
Part 1:
You should be able to create a calculated field(Analysis->Calculated Field) and name it something like "Number of Records". In the query box just set it to 1 and select "Okay".
This new field will be selectable in the measures. Drag it into your table in the columns area and it should add a count next to your averages.
Part2:
In your measure values box you should be able to right click you measures. This will bring up a list of options including "Filter". Select this option.
On the SUM(Number of Records) set it to "At Least" = 2. Then right click on the AVG(Ratings) measure and set it to "At Most" = 3
Put Products on the Rows shelf.
Then right click on that Products field on the Rows shelf and change ITT from a dimension to a measure. Be sure to choose Count Distinct for the aggregation.
Finally, right click on the field again and change it from continuous to discrete.
This shows how many different products each person reviewed, no matter how many characteristics they rated. If you want the number of ratings, use count instead of count distinct. Or just Sum(number of records), again set to discrete