Calculated Value Percent of Subgroup Spotfire - spotfire

I want to create a calculated value in Text Area that show me % of a column with a certain status over all status. How can i do this?
Example:
Count([Protocol]) of Status 'A' / Count([Protocol]) of all status, and show this like a percent.
Sum([Value]) of Status 'A' / Sum([Value]) of all status.

You can nest an if statement inside a sum to get the numerator of each expression (counts or sums). They both have a sum for the numerator, but the if statement returns differently. For the count, you return 1 if the status is the one you are looking for and 0 otherwise. This effectively performs a count. For the case where you actually want the sum, the if returns the value of your Value.
Sum(If([Status]="A",1,0)) / Count([Protocol])
Sum(If([Status]="A",[Value],0)) / Sum([Value])

Related

How to evaluate a sum in excel to return 0 if the sum of two values is >0 (for my data I do not care about Positive values)

I am summing loads for member design and have the correct values for downforce. However, when I use my formulas for uplift (-) if there is no uplift it returns a positive value which is objectively correct however it is not needed for my purposes. I only need negative values for uplift.
I've tried
sumif(Range,SUM(Range)<0,Sum Range)
sumif(Range,"<0")... this just returns the only negative value which is not what I need
basically, i still need to sum the data but if it returns a positive it should return zero, and if it returns a negative keep the value
Ex.)
2+3 should = 0
3-9 should = -6
You can use MIN to not allow the value to become greater than 0
=MIN(SUM(A1,A2),0)
This will make any positive number 0 because 0 is lower than any positive number.
Something like this?
=IF(SUM(J87+K87)>0,0,J87+K87)

Excel IF AND statement with percentage output

I have a dataset of co-ordinates, except the co-ordinate is split into two column X and Y.
I'm trying to find the percentage of co-ordinates in a single quadrant, and thought IF/AND statements would work i.e.
IF "numbers in X Column is between -5 and 0" AND "numbers in Y is between -5 and 0" then display total as Percentage of all data
IF "numbers in X Column is between 0 and 5" AND "numbers in Y is between 0 and 5" then display total as Percentage of all data
Etc..
I think that may be the easiest way but I'm stuck on three things;
How to do it for negative numbers
How to do "is greater than a number BUT less than a number" (rather
than just greater/less than), and
How to show results as a percentage (I only know how to return a
TRUE or FALSE) i.e.:
=IF(AND(A2:A100>5,B2:B100>5),TRUE, FALSE)
If you have the newest version of Excel you can use FILTER.
For example, if you are looking for the percent of coordinates in Q1 (0<=X<=5, 0<=Y<=5), you can use something like:
=ROWS(
FILTER($A$2:$B$100,
(($A$2:$A$100>=0)*($A$2:$A$100<=5)*($B$2:$B$100>=0)*($B$2:$B$100<=5))))/
ROWS($A$2:$A$100)
If not, then a simple way is to do what you were originally trying in a helper column, and divide the results by the total rows.
To answer your questions:
For negative numbers, e.g. Q3, just use negative numbers. Something like:
=IF(AND($A$2:$A$100>=-5, $A$2:$A$100<=0, $B$2:$B$100<=0, $B$2:$B$100>=-5),1, 0)
Logically, it is not really "greater than a number BUT less than a number", but "greater than a number AND less than a number". The example in question 1 shows that in action.
To get as a percent, you add up all the values, and divide by the total. In an IF statement you can return anything (format is =IF(test_is_true, value1, value2)), so in the above example, I elect to return 1 for whenever a row meets our criteria.

Percentage Over Column Total Calculation

I am trying to do a cross table with a column that calculates the percentage the column total (third column from the left). I've been trying to follow some examples found in my Google searches but can't seem to get it to work.
I tried to insert this custom expression in my subsets:
Count() THEN [Value] / Sum([Value]) OVER (All([Axis.Rows]))
But I get this error: The expression is not valid after 'THEN' on line 1 character 9.
If someone still trying to do this you can do this :
Count() then Sum([Value]) Over (AllPrevious([Axis.Rows])) / Sum([Value]) OVER (All([Axis.Rows])) as [Cumulative Sum]
That will give you this result :
Where you have "(Column Names)" in Horizontal, [country] in Vertical axis and the sum and cumulative sum in the Cell Values.

Rounding Summarized Saved Search Results

I created a saved search on sales orders to calculate days between order date and ship date, grouped and averaged by class (the formula is cased to distinguish between 'Wholesale' class and all others). The numeric formula is:
CASE WHEN {class} = 'Wholesale' THEN {actualshipdate} - {startdate} ELSE {actualshipdate} - {shipdate} END
The summary type for the formula result is average. The summary-level results have way too many decimal places. Is there a way to round the summarized results to a pre-defined number of digits?
I have tried using the ROUND() function, both inside the CASE statement and as a wrap-around. I've also looked through general preferences for rounding defaults and haven't found any.
In order to round the result, you should implement you own average calculation and rounding.
Add the following result field besides the class grouping field that you already have:
Field : Formula (Numeric)
Summary Type : Maximum
Formula : ROUND(SUM(CASE WHEN {class} = 'Wholesale' THEN {actualshipdate} - {startdate} ELSE {actualshipdate} - {shipdate} END) / COUNT({internalid})),2)
Basically, you are doing here your own analytics.
Since the results are grouped, each result fields contains the whole result set of this field which allows you to add analytical functions on this group.
The summary type is MAXIMUM, just in order to show one result, so it can also be min or avg, no difference.
The function is calculating the sum of your formula and dividing it by the records count to get the average.

Summing the max values when grouping other then exact

I will explain step by step. I'm trying to get one single integer value for a certain key set.
So let's say that i have the following map function
function(doc) {
emit([doc.key1, doc.key2, doc.key3], doc.integerValue);
}
the doc.IntegerValue in this case is a sequence. So let's say that someone makes 0,10,20,30 progress and after that he starts on a new sessionId with once again 0,10,20,30,40.
Now i was trying to reach the following.
1) When doing a group exact it should ouptut the max integerValue found.(first 30, second 40)
2) When doing a group on level 2 it should output the sum according to the max values on scenario 1. So that i can count the total value. So let's assume that key2 and key1 where the same in both examples, it would give me 70.
3) when doing a group on level 1 it should also give 70. as it are the same 2 rows as in the last scenario.
The _stats reduce function does not do the job as it only gives the max of the whole group or the sum of the whole group and my request is a combination of both.
besides that i know, i have the option to leaf the grouping thing out, and then select with startKey and endKey, but i want to check if it is possible with the grouping option.
Thanks in advance for any ideas.!
If you are not interested in stats, why don't you just output the single highest value of integerValue* in your view and use _sum as the reduce function?
// map function
function(doc) {
if(!doc.integerValue || !(doc.integerValue instanceof Array)) return
return ([doc.key1, doc.key2, doc.key3], doc.integerValue.sort().reverse()[0])
}
// reduce function
_sum
This will mean
group_level=exact will output the highest value of the sequence
group_level=2 will output the sum of those single highest values of each sequence
group_level=1 will do the same.
*Assuming integerValue is an array -- I wasn't 100% sure from your question.

Resources