A filter to apply only if only one item from two other filters are selected - tableau-api

I have two filters for WeekNumber and Employee (name). I also have a column that shows the SUM of hours the employee has worked. Let us call it SumHours.
What I want to do is to specify the employees who have overworked, which is
if the number of weekly hours is more than 38.
If the condition applies I'd like to highlight them by adding a background color to their row.
Adding the above filter to the entire table is not a problem. What I want to do is for this filter to appear only if (1) one week and (2) one employee have been selected. Because otherwise the calculated field will highlight the employee if they have overworked in average.
How can I create a condition in my calculated field so that a condition is checked in two different places? I have found the SIZE() function but then we should also select the option Compute Using... to assign it to a specific filter. But apparently one cannot do that to two filters.

If I understand your setup correctly, I think a level-of-detail calculation might do the trick. This is pseudo-code, you will need to adjust for your dimension names. With LOD, you are getting the value of the hours worked per employee and week, regardless of which dimensions you have in your rows or columns.
if {FIXED Employee, WeekNumber : sum(HoursWorked)} > 38 then "Highlight" end
Then add this calculated field on the color marks card.
More about level-of-detail calcs can be found in Tableau's online help.

Related

Look up an account then average associated values excluding zeros

On one sheet, I have account code and in the cell next to it, I need to look up the account code on the next sheet to average the cost excluding those cells that are zero in col. b from the average calculation.
The answer for London should be: £496.33 but having tried various sumifs / countifs I cannot get it to work.
You probably need COUNTIFS which -- similar to the SUMIFS you are already using -- allows to define multiple critera and ranges.
So, if the column R contains the values, you want to build the average upon, and the column H in the respective row must equal $B$28 to be included in the sum, the respective COUNTIFS looks as follows
=SUMIFS('ESL Info'!$R:$R,'ESL Info'!H:H,$B$28)/COUNTIFS('ESL Info'!$H:$H,$B$28, 'ESL Info'!$R:$R, "<>0")
ie additionally to the value in the H-column to equal B28 it also requires the value R-column (ie the actual number you are summing up) to be different from 0
You could also add the same criteria 'ESL Info'!$R:$R, "<>0" to your SUMIFS, but that isn't necessary, because a 0 doesn't provide anything to you sum, thus it doesn't matter if it's included in the sum or not ...
And depending on the Excel version you are using, you may even have the AVERAGEIFS function available, which does exactly what you want
=AVERAGEIFS('ESL Info'!$R:$R,'ESL Info'!$H:$H;$B$28,'ESL Info'!$R:$R,"<>0")

How to divide an Aggregate and Sum function

I am working in Tableau and trying to create a formula that will return me the value of each customer that walks into a store by dividing Net Sales / Traffic. When I try to combine the two separate formulas, it gives me the following error: Cannot mix aggregate and non-aggregate arguments with this function. The two functions I created that I'm trying to divide are:
SOT = (SUM([Sales Net])-SUM([Sales Gcard Net]))/SUM([Traffic Perday]) and SOT Goal
When I look at it in Tableau, it's stating that SOT is an aggregate function. How do I work around this to be able to get
SOT / SOT Goal
Aggregate variables are values that are calculated in the view, and depend on the level of aggregation in Tableau. e.g. sum(Sales) will show different values in Tableau if it’s next to a Region dimension, or if it’s next to a Category dimension.
In order to avoid the errors you can use many solutions. My favorite is indeed LOD expressions. In your view, though I do not have required sample data and therefore, I cannot try my hands on different possibilities here, I suggest that this should work-
SOT = ({SUM([Sales Net])}-{SUM([Sales Gcard Net])})/{SUM([Traffic Perday])}
Do remember that this solution will over-ride your filters and if you are using filters you have to add all those to Context.
EDIT
While trying different possibilities remember these things...
{SUM([Sales])} will sum the sales over entire data and {} i.e. curly braces wrapped around the sum function will cause to return the value as non-aggregate. In other words, this will work as LOD and if you'll add this field to view, the sum of entire sales will be shown against each row.
{FIXED [DIMENSION NAME] : sum([Sales])} will sum sales separately for each Dimension value. Fixed statement (LOD) again returns the value as non-aggregate value. if you'll add this field to view, the sum of entire sales for that dimension will be shown against each dimension.

Pick group totals, grand totals and normal summarization in Tableau

I am trying to calculate average of 2 columns in another column in Tableau but difficult part is grand total is not getting average instead it is the sum of 3rd calculated field.
A B Calculated field
10 5 2
6 3 2
T 16 8 4 (Here I should get 2 instead it is taking sum of column)
Here I am unable to write separate formula for row totals and grand totals, Only one formula (Calculated Field) is allowed and when I am dragging on sheet it is by default aggregating to sum.
Note: I am expert in Crystal and BO but beginner in Tableau.
Update
Code used for LoD
{FIXED [Product Category]: AVG([Sales])}
Below image is what I got after implementation I have tried with 2 columns but the result is same if I use only one column (I am trying to get the average of sales)
You are almost there - the Grand Total by default does a SUM function you just have use the Total All Using --> Average option.
Output : Level wise SUM(Profit) later averaged across columns and rows. (Show Column Grand Total & Show Row Grand Total active)
Update: Answering the question below. To get the Row-wise avg (which is Cat1-vag in this case) you could just drop the measure and change it to AVG(). Since you needed in a Calculated Field you could use a Simple FIXED LOD. You can also uncheck aggregated measures from Analysis dropdown and have no Dimension in column or row like unlike what this example shows and still get three different averages. Cheers.
{FIXED [Cat1]:AVG([Profit])}
Check out this very smart work around from Joe Mako.
https://community.tableau.com/thread/112791
create a calc field like:
IF FIRST()==0 THEN
WINDOW_AVG(SUM([Sales]),0,IIF(FIRST()==0,LAST(),0))
END
duplicate your Category field
place "Category (copy)" on the level of detail
set the compute using for the calc field pill to use "Category (copy)"
The window function in the calculated field only takes into account what's in the view, and aggregate based on those number.

compute difference between 2 ranked columns in tableau

I am trying to find the difference between 2 columns in tableau. The catch though here is that each column is ranked based on a value. The difference i need is between these 2 ranked columns
The rank is computed using the table calculations rank function. Attaching the picture for more information
I am assuming "current" and "prior" are calculated fields.
Just create a new calculated field, here I'll call it "Result". In this field just minus your one from the other so:
[Current - Prior]
Then pull this new field into your measures values on your sheet.

Get 2 max date in Tableau

My requirement is to get the second max date available in report and filter the data set on this.
I tried something like this:
datediff('day',dt,max(dt))=1
Referred to this link
any help?
You're going to need Tableau 9.0 for this. Basically because any calculation you do on Tableau depends on the level of detail you have on the worksheet (the dimensions you put in there). So datediff('day',dt,max(dt))=1 won't work. First because you're mixing aggregated fields (max(dt)) with non-aggreagated (dt). Second, because the aggregation depends on the dimensions in the workfield.
But Tableau 9.0 has a new awesome feature, called Level of Detail calculations. It allows you to perform calculations in the level of detail you choose, depending not on the dimensions on the sheet. It is also calculated BEFORE any calculation on the worksheet (just after context filters).
Now to the answer. First I'll figure out what is the max(dt). Let's call it max_dt
{ FIXED : MAX(dt) }
This will calculated the maximum of dt in all your database
Now to get the second max, you can go like this:
{ FIXED : MAX(IF dt != max_dt
THEN dt
END)
}
This will calculated the maximum of dt, ignoring those who are equal to max_dt (that is the true max(dt)). Therefore, the second max.
Take a look on those LOD calculations. They were just released, I'm having tons of fun with them right now
If the view has date dimension
The easy way to do this,is to create a calculated Last()=1
then filter off the records that evaluate to TRUE