How to concatenate string and integer in if condition in tableau - concatenation

I am trying to concatenate country with its rank based on sales in if condition like
IF [TOP 20 COUNTRIES] THEN [COUNTRY]+[RANK] ELSE "OTHERS"
here I am getting error saying can not mix aggregate and non aggregate fields in if condition. then I tried like
IF ATTR( [TOP 20 COUNTRIES] ) THEN ATTR([COUNTRY])+[RANK] ELSE "OTHERS"
then also I am getting error saying Boolean can not aggregate.
Here [TOP 20 COUNTRIES] is SET of Top 20 countries based on SALES
please help me in this

The problem is to mix aggregated arguments (e.g., sum, count) with non aggregate ones (e.g., any field directly). And that's what you're doing mixing aggregated arguments non aggregate ones.When creating a calculated field, you may see a “Cannot mix aggregate and non-aggregate arguments to function” error message. This message displays when a calculation contains a mix of disaggregated values and aggregated values. Aggregations allow you to look at numerical data in some sort of summary form, such as sum and average.

Related

how can i get alert when i get 2 different item in the oracle query while fetching the data?

I want alert when i am fetching two different item in the oracle query
basically i want to check what ever i am searching it should from one policy when every i any getting two different policy i should get alert or some remark in another query that more then one item got fetch
for example
when i am fetching the data from oracle using the query i want the single item in the column and if i get multiple item i should get the alert
select * from table policy_id in ('100')
By asking, "when do I get 2 different items", or "when I have two distinct values" for a given key, you must aggregate rows in order to compute an aggregate value. COUNT, SUM, MIN, MAX, AVG, STDDEV, etc... are all aggregate functions that operate on multiple rows. But for them to operate on multiple rows, you must raise the granularity of your data to a higher level, or what we call "group by". Group by the key column(s) and aggregate across your fact columns to summarize those facts within those groups.
In your case, group by the columns for which you want to see unique values in separate rows. Then count how many rows were included in each group by using the COUNT(*) function. You may then wrap the output of that in a CASE or DECODE to conditionally test that output and return something different based on that output. In my example, test for 1, otherwise if more than one, you have multiple rows sharing the same key values. DECODE arguments are (test value, comparison value, result-if-true, result-if-false). So below will show "multiple policies" if there are 2 or more rows with the same policy,claim, req values, and NULL/empty if there are not.
SELECT policy,claim,req,DECODE(COUNT(*),1,NULL,'multiple policies') alert
FROM table
WHERE policyid = 100
GROUP BY policy,claim,req

How to specify a column field in a calculated field formula when you have the same value evaluated as a count and a sum?

I am using a pivot table to summarize our status of completion of a project. The first value of the pivot table gives me a count of the entries in the spreadsheet column that have a value greater than 0. The next value of the pivot table gives me a count of the total estimated quantities from the spreadsheet. The third value gives me the sum of the entries from the same column of the spreadsheet that the first value uses in the pivot table. The final value of the pivot table is a sum of the total estimated quantities from the same column from the spreadsheet the second values uses for the pivot table.
My current working formula will only evaluate the SUM columns in the pivot table and is the following:
=iferror('Quantities Complete'/'Total Est Quantities',0)
This gives me a percent complete based on the SUM of those two columns from the spreadsheet. These values can differ because the first is a real value and the second is an estimated value. What I want is the below formula which I will put how the data is summarized in parenthesis for simplicity of understanding.
=if('Quantities Complete'(COUNT)='Total Est Quantities'(COUNT),1,iferror('Quantities Complete'(SUM)/'Total Est Quantities'(SUM),0))
This formula would allow me to evaluate if the count of complete items matches the total estimated items, if so the calculated field value is 100% regardless of actual sum values. Otherwise, it gives a percent complete based on sum value which is more accurate because each item can have vastly different values.
How can I refer to the 2 different uses of the columns in a calculated field formula?
I have tried the renaming the column headers to 'Items Complete' and 'Item Values' but the formula does not accept those and gave a parse error. I have tried using the "COUNTA of" or "SUM of" prefix for the column fields. I also tried typing the name as shown when I hover over the value field in the edit window which I tried in these methods: 'Quantities Complete' (Items Complete) and 'Quantities Complete (Items Complete)'. All of these yielded a parse error. I can't share my spreadsheet due to confidentiality requirements, but all I need to know is how to refer to the two different column headers that have the same name from what I can tell.

SSRS - Sum of an aggregated field

I have a report, that shows the individual sales commission for each employee.
The expression for the Sales Commission is:
=Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value
Now I want to add a total for this field. If I just right click the cell and click on Add Total, it works but gives out the wrong total.
If I try to sum the field like this:
=Sum(Reportitems!GO_Prov.Value)
I get the error:
The Value expression for the textrun 'Textbox93.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers.
Is there a workaround to sum the aggregated field of this tablix? Maybe with a code?
Thanks in advance.
Update1:
Unfortunately i don't know how to write custom codes. But I found this code:
Public Total_lookup_Sum As Integer = 0
Public Function Lookup_Sum(ByVal value As Integer) As Integer
Total_lookup_Sum = Total_lookup_Sum + value
Return value
End Function
The expression i used for the Sales Commission is now:
=Code.Lookup_Sum((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
And the expression for the field where i would like to get the sum is:
=Code.Total_lookup_Sum
Now i get the error:
There is an error on line 0 of custom code: [BC30205] End of
statement expected.
Is there a way to solve this?
Scenarios like these can be tricky in SSRS. From your description (even though the screenshot doesn't really show everything), I'm guessing that you've got rows grouped by salesperson. In your column that's calculating the commission, you've got a sum of "Total_commission", but you've just got the "Individual_Factor" value not aggregated. Again, having a guess, but each underlying row (by employee) must have the same "Individual_Factor" value (so actually using Min(Individual_Factor) would give the same result).
But then, when you try and just take the same formula (or even a derivation of the formula), and make an overall aggregate of all of the rows, how does SSRS know which "Individual_Factor" value to use? You don't want Min() or Max(), because that would just be the lowest or highest value across all of the salespeople.
Your suggestion of a workaround via code is generally the way that I approach this. You need a report variable, something like "Commission_Grand_Total", and then you need a function in the report code that accepts 1 parameter, and in the function you'll add the parameter value to the variable. The easiest thing to do is to make the parameter the return value of the function.
Then, in the field where you currently have your commission formula (on the salesperson row), the expression in that field becomes =TheFunctionYouCreate((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
By passing the formula to the function, you're achieving two things:
The function will take each salesperson's calculated commission and add it to your report variable
The function will output the parameter value that you passed in (since you want to display the calculated commission amount on each salesperson's row)
Lastly, to display the overall total, the expression for that field is just the report variable that holds the overall total (that has been cumulatively added to as SSRS wrote out each salesperson's record)
TIP: I sometimes do this same sort of thing, but if I don't want the row-by-row value to be shown (I just want the cumulative total to be calculated), just put the expression that calls the function in a hidden column. SSRS will still run the function as it renders each row, but obviously it's just not displaying the result of the function.
Some MS reference for report variables and code
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/built-in-collections-report-and-group-variables-references-report-builder?view=sql-server-ver15
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-code-to-a-report-ssrs?view=sql-server-ver15
This is untested unfortunately but...
assuming you have a rowgroup for employee called EmployeeGroup then the expression would look like this...
=SUM(
Sum(Fields!Total_Comission.Value, "EmployeeGroup")
* Parameters!Distribution_Factor.Value
* FIRST(Fields!Individual_Factor.Value, "EmployeeGroup")
)
The inner expression reads as
Sum of Total_Comission with current employee group
... multiplied by Distribution Factor
... multiplied by the first individual factor with the current employee group
The outer expression just sums all the individual employee level sums.

Generate Distinct List and Sum On Conditional VLookUp

Sample Data Sets
I'm trying to write a formula that can fill in revenue amounts in Table3. What I need is for it first to search through Table1 and return an array with each unique ID referenced by the domain.
So for a.com it would return {1,2,3}.
It would then find the revenue value in Table2 that is associated with that ID.
For the array above it would be {100,200,400}.
It would then sum those values to arrive at {700} which would populate cell H3 or [#[Sum of Revenue]] for "a.com".
I've tried using sumproduct and combining it with variations of
{=INDEX(Table1[ID],MATCH(0,COUNTIF($H$2:H2,Table1[ID])+(Table1[Domains]<>$G$3),0))}
But I'm having trouble at arriving at the full array and not just the first, second, etc. unique value in the array. I also don't know how to end up with the revenue values in the array instead of just the IDs. Any help is appreciated.
This is what ended up working:
{=SUM(SUMIF(Table2[ID],IF(FREQUENCY(IF(Table1[Domain]=[#Domain],Table1[ID]),Table1[ID]),Table1[ID]),Table2[Revenue]))}

Generating Working Hours using SQL Server Query

I have this data and I need to generate a query that will give the output below
You can do this kind of groupings of rows with 2 separate row_number()s. Have 1 for all the data, ordered by date and second one ordered by code and date. To get the groups separated from the data, use the difference between these 2 row_number()s. When it changes, then it's a new block of data. You can then use that number in group by and take the minimum / maximum dates for each of them.
For the final layout you can use pivot or sum + case, most likely you want to have a new row_number for getting the rows aligned properly. Depending if you can have data missing / not matching you'll need probably additional checks.

Resources