Tableau creating a calculated percentage (non-aggregate) based on an aggregated total - tableau-api

Either I am the first person to ever need to display percentages in Tableau or I do not know what to search for! I highly suspect it is the latter...
I believe what I am attempting to ask is how to make a calculated non-aggregated field by dividing by an aggregated number. Although I would prefer just to be able to display the percentages instead of a whole number.
This is how I would do it in Excel:
The data that already exists is Column A and B. In Tableau these would be non-aggregated. What I need to do in Tableau is to generate what is column C (also non-aggregated) because it does not exist in my data. In excel, all I did to get the aggregate number (total) of column B was:
sum(B1:B4)
And for the column C:
=B1/$B$5
But I can't seem to do this at all in Tableau. When I try to use the same syntax, I get an error message: "Cannot mix aggregate and non-aggregate arguments with this function."

Instead of having a calculated field, you can use a Quick Table Calculation on the column.
Right-click the pill of your data > Quick Table Calculation > Percent of Total. This will show the percentages instead. If you want to keep both, just duplicate column b first and then add the table calculation to the new column.

Related

how to multiply variable to each element of a column in database

I am trying to add a column to a collection by multiplying the 0.9 to existing database column recycling. but I get a run time error.
I tried to multiply 0.9 direction in the function but it is showing error, so I created the class and multiplied it there yet no use. what could be the problem?
Your error message is telling you what the problem is: your database query is using GROUP BY in an invalid way.
It doesn't make sense to group by one column and then select other columns (you've selected all columns in your case); what values would they contain, since you haven't grouped by them as well (and get one row returned per group)? You either have to group by all the columns you're selecting for, and/or use aggregates such as SUM for the non-grouped columns.
Perhaps you meant to ORDER BY that column (orderBy(dt.recycling.asc()) if ascending order in QueryDSL format), or to select all rows with a particular value of that column (where(dt.recycling.eq(55)) for example)?

Tableau Target Vs. Actual - Can not get totals to show correctly

I am having trouble showing the correct totals in my tableau worksheet.
I have supervisors that are part of specific zones that need to complete a certain number of tests in different categories. For example, supervisor 15716 must complete 8 tests in category 1. I need to show the target, which is a number stored in the database and show the actual number of tests in that category that have been completed within a date range. I have it working, but Im not sure if I did it correctly because I can not show any totals.
System target - number stored in database
CountOfSheetID - calculated field
Percent Compliant - calculated field
Try this approach -
First define a calculated field called [Within Date Range?] as
[Date] >= [MyStartDate] AND [Date] <= [LastSelectedDayOfMonth]
and put that new field on the filter shelf, only including data where [Within Date Range?] is True. (You could also just filter the [Date] field if that is flexible enough for you)
The you don't need the CountofSheetId calculated field at all. If you want to know how many records have a non-null value for [SheetID] within your date range, you can simply drop [SheetID] on a shelf and choose to treat it as Measure with the aggregation function COUNT()
Then just build your visualization to show the counts you want (not percentages, the actual counts)
Finally, you can convert counts into Percentages by clicking on the pills for your Measures and choosing Percentage under Quick Table Calcs. You'll want to experiment with the "Compute Using" setting to tell Tableau how to compute your percentages -- i.e. define percentage of "what".
Percentages are implemented as table calcs in Tableau. Read the help to understand table calcs, especially the description of partitioning and addressing.

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:

Counting the number each element in a comma seperated column in Tableau

I am new to using Tableau.I want to count the number of times each genre appears in the data set.
In the data set(image attached), I have several genres for one show. I want to count the number of each genre in the data set and display it in Tableau
If you have access to database, then take the dump of data in a excel.
Split the data by , and then create a individual column for every word in the genre column.
Now take the excel as source to tableau, In tableau pivot the splitted columns of Genre.
Go to sheet in tableau, Place the pivot field values in rows and count of pivot field values as measures.
You should be able to see the desired result.
This can be done by an alternative method if you know the distinct list of all genre.
what you need to do is to create a separate calculative field for each Genre using
if contains(Genre,'action') then 1 else 0 end
and then use the Sum of these field as the count of Series per genre.
I know this is a hideous task but, it can be done if you do not have any other option.

Second Max in Tableau Calculated Field

How can I get the second highest value from a field in a calculated field. In excel I would use the large function but there doesn't seem to be a tableau equivalent. I would prefer to do the calculation in Tableau instead of using a pass through function.
Here are two alternatives.
First, if you want the calculation to happen on the data source side, You could write a LOD calculation to find the max of your field, name it myMax
{fixed [My_Dimension1], [My_Dimension2] : max(myField)}
Whether you use fixed, include or exclude scope for the LOD calc depends on how you want to scope your analysis.
Then write a row level that returns the field value if it is less than the LOD calc, and implicitly null otherwise, name myFieldExceptMax
if myField < myMax then myField end
The max of that row level calc would be your answer.
max(myFieldExceptMax)
Alternatively, if you want to operate on the client (tableau) side to find the penultimate aggregated query result, you can use on of the ranking table calc functions, and the filter to only show the second ranking result.