Fix the "Cannot mix aggregate and non-aggregate arguments with this function" error when creating a calculated field - aggregate

I need to create a Dimension (calculated field) that depends on a filter.
My dataset has four columns: ID (Int), Variable Name (String), Value (Int) and Client ID (String). For each client ID there will be a value for each type of variable.
There are 6 types of Variable Name, and for each row there is unique ID.
I'm using a filter by Variable Name so there is one, and only one variable type available at the same time.
In order to display it in a stacked bar chart by that dimension, I have created this calculation field (In reality if has six IFs, but I'll use just one to illustrated it):
IF ATTR([1 (ML_Output)].[Variable Name])= "Interest Rate" THEN [Interest Rate] END
That way, when the filter is in "Monthly Interest Rate", the ATTR function should show the only type of variable available in the Variable Name field, which would be "Monthly Interest Rate". The problem is that it shows the "Cannot mix aggregate and non-aggregate arguments with this function" error.
I've been trying to solve this with many tutorials, but none of them work for one reason of another.
Any ideas?
EDIT:
PS: The original calculation that was doing what I wanted used a Parameter. However, since parameters won't update automatically when the dataset changes, I can't use it anymore. The original calculation was:
IF [Parameter 1]="Interest Rate" THEN [Interest Rate] END
I need the calculated field as a dimension. So, if I aggregated the result of the calculation, then it would be a measure, and that can't be used to create a stacked bar.

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

SSRS Grouping Summary - with Max not working

This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.

Perform analysis on last three values of a FileMaker dataset

My end goal is to have a box change color when the last 3 records input into a field (based on the time of input) in FileMaker achieve a certain criteria (ex. variance < 2). I would like to know how to make this happen, or how a calculation/script can be written to only look at the last 3 records.
There are several ways you could approach this. A simple one would be to use a script to:
Show all records in the given table;
Unsort them (assuming they were entered in chronological order; otherwise sort them by creation timestamp);
Omit all records except the last three;
Get the value of a summary field defined as Standard Deviation of your value field;
Set a global variable/field to the square of the returned value.
Then use the global variable/field to conditionally format your "box".
If you don't want to use a script, you will have to define a relationship in order to get the last three values in the table, regardless of the current found set and/or sort order. Or you may use the ExecuteSQL() function for this.

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.

ssrs sum function in textbox

I have 2 datasets in my report. And I need to put a number of rows that meet a certain condition in a text box.
Here's what I have so far:
=Sum(IIF((Fields!OPEN_TIME.Value, "calls")=Parameters!Date.Value,1,0))
I get following error while running the report:
The Value expression for the text bix uses an aggregate expression without a scope. A scope is required for all aggregate used outside of a data region unless the report contains exactly one dataset
What do I miss?
Here if you are specifying a dataset name to a field like this "(Fields!OPEN_TIME.Value,"calls")" its a syntax error.. if you are using the field in a table which is assigned to dataset1 and table is assigned to dataset2 or field in a text box, then the field should be used with aggregate or "First", "Last"
Example:
first(Fields!OPEN_TIME.Value, "calls")
last(Fields!OPEN_TIME.Value, "calls")
sum(Fields!OPEN_TIME.Value, "calls")
Count(Fields!OPEN_TIME.Value, "calls") ...etc
In above scenario rather than taking a textbox, take a table with single cell assign the dataset "calls" to it then go for below expression:
=Sum(IIf(Fields!OPEN_TIME.Value = Parameters!Date.Value, 1,0))