Dynamically display the measures based on filter value in tableau - tableau-api

I had a requirement where i have to display measures based on a filter created on Dimension value.
For eg
Dimension Filter Value Dropdown --> Value1, Value2, Value3
Measures --> Measure1, Measure11, Measure2 Measure21, Measure22, Measure3
When I select
Case 1 :
Filter -> Value1
Measure To display -> Measure1, Measure11
Case2 :
Filter -> Value2
Measure To display -> Measure2, Measure21, Measure22
Case3:
Filter -> Value3
Measure To display -> Measure3
I am new to tableau development and last few days i started using this . I googled few and found one resource in the below link
Choose Measures dynamically
But in the above link they shown based on filter value they display only one measures not multiple measures.
I need to display multiple measures based on filter value.
As Explained i followed the process but don't know how to include multiple measures in the below code in Calculate field
CASE [Filter Parameter]
WHEN “Value1” THEN Measure1, Measure11
WHEN “Value2” THEN Measure2, Measure21, Measure22
WHEN “Value3” THEN Measure3
END
Hope it is explained well, please let me know .
Thanks

You'll need to both transpose your dataset and create a flag to be used as the filter value.
To transpose your data:
Edit your data source
Click the first column you want to transpose and then shift + click the last
Click Pivot
Now navigate to your sheet to work with the data
I'll create a field to just pull out the number for the 'MeasureN' string so it's easier to create the filter, but this isn't necessary.
Now I'll write the calculation to be used as a filter that mirrors the logic you shared.
Arranging the pills on the screen like this...
Hopefully provides you with the functionality you were looking for. Happy vizzing!

Related

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.

Spotfire - Filtering a Table by Values in a Calculated Column

I am trying to filter a table visualization of all of my data by looking to see if a Study Number contains Activity A. If a Study Number contains Activity A then I want to filter for all rows containing those Study Numbers even if the Activity is not A. See mock data below. In my real data set I have ~55,000 rows.
I have created a calculated to return Study Numbers if Activity= A but I am not sure where to go from there. Thanks for any help.
If(UniqueConcatenate([Activity]) OVER ([Study Number])~="A","Y","N")
Will give you this resulting column that you can then filter on (or you can use the formula as a Data Limiting Expression:

Filtering by a calculated measure involving multiple fields in Qlik Sense

I am trying to use a calculated measure as a way to filter my data, but it's looking more difficult than expected. Let me explain through an example.
I have data of the following type, with two dimensions - one is a unique ID, the other a category - and four measures.
Initial table
My first step is to rank each element by its score, where the ranking is evaluated within the same category. I therefore create a new measure:
=aggr(rank(sum(Score1)), Category, UniqueID)
I do this for all three scores, resulting in three new calculated measures. My final calculated measure is the average of the three rankings. Below the example, the calculated measure of interest is the one in bold. Note that in my real world calculation I directly evaluate 'New Measure', without creating the intermediate columns 'RankingScore'.
Data with newly calculated measure
Note that this measure is tricky, as it changes according to previous selections. Say, for instance, that I select only entries with 'Amount' > 1000. The relative rankings will change and therefore also 'New Measure'.
In my actual App I need to filter my entries by 'New Measure', after I've done some previous selections on fields like 'Amount'. If it simply were a field, I would normally have created a filter pane, our used the qsVariable extension to have a slide range, to select only rows with 'New Measure' above a set threshold. Unfortunately it seems I cannot do that with my calculated measure.
How would you approach the problem? I was wondering, for example, if it were possible to 'convert' my new measure to an actual field, after all previous selections have been done, but perhaps this is nonsense.
Thank you in advance, and apologies for the long post!
If I'm understanding correctly, I believe this solution should work:
Create a variable for your slider: new_measure_slider.
Create a New Sheet Object -> Slider/Calendar Object.
Configure your slider to control your new new_measure_slider variable.
Create a calculated dimension in your chart substituting your 'New Measure' formula (the one you stated was an average of the three ranks). It should be a conditional like this:
=if(aggr([your average formula here], Category, UniqueID) >= new_measure_slider, [Category], null()).
Basically, compare your formula to the new_measure_slider variable. If true, use the Category (or UniqueID, whichever you need) as the dimension, if false, null().
Check the 'Suppress When Value is Null' checkbox on your new dimension. This is key. This is what will actually filter your chart.
In the chart properties, Presentation tab, click on your new calculated dimension and hit 'Hide Column'. We don't need to see this because we are using it only as a filter.
You can tell QV to ignore your filtering in the field Amount by adding "Amount=" to your set analysis.
I dont know how your average calculation looks like but maybe:
(aggr(rank(sum({<Amount=>} Score1)), Category, UniqueID) +
aggr(rank(sum({<Amount=>} Score2)), Category, UniqueID) +
aggr(rank(sum({<Amount=>} Score3)), Category, UniqueID)) / 3

Count the number of instances of values across multiple dimensions in Tableau

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:

Tableau table hides categories with no data - how to prevent?

I have Tableau report where I am showing data by category in columns.
The table shows all columns when there is no filter on data. But when filter is applied, some of the categories do not have data, so table shrinks, hiding columns without data
Is there a way to always show columns regardless of data or not in that column?
Please see screenshots below.
Go to Analysis >Table layout> Show columns with no data or
Analysis>Table layout>Show rows with no data
The next step depends on whether your "disappearing" fields are dimensions or measures.
If you want to force the display of members for specific dimensions, then one (kind of complex) solution is to use an advanced Tableau feature called data blending to force the existence of dimension members, even if there are no related measure values. The trick is to make a simple data source, say a text file, that lists the members of each dimension. Use that source as the primary data source, and make the original data source the secondary source.
Go to Analysis >Table layout> Show columns with no data or Analysis>Table layout>Show rows with no data
Also You can right click on header and select show missing values if you are using line chart.
Solution 1: (When you’re working with Dates or Numeric bins)
Right click on the numerical or Date column to extrapolate the missing values. As you notice in the lower part of the screenshot, this will not work on Categorical data !
Solution 2: Categorical Data
As indicated in the accepted answer, Analysis > Table Layout > Show Empty Rows will get you the same result for Categorical (Text) Data
Solution 3: Calculated Columns
If for some reason, none of the 2 above point & click solutions work, you can create calculated columns to calculate the measure for each of the Categories with the below formula and then line them up on the Columns to achieve the same result
Profit (Category 1)
IF MyColumn = "Category 1" THEN
Profit
ELSE
NULL
END
Profit (Category 2)
IF MyColumn = "Category 2" THEN
Profit
ELSE
NULL
END
Not the most convenient solution when you have hundreds of unique values in your column, but nevertheless a workaround !