Spotfire Between two values calculated column - calculated-columns

I have a Calculated Column see syntax below.
What I trying to achieve is this. If there is a piece of text in [Part of Group ?] and there is RUBU or CABU in [ISPG Grouped] column then get 10% of [Final] column. But what I also want to say is that if there is no text in [Part of Group ?] and and there is RUBU in [ISPG Grouped] column and the value of [Final] column is between 10,000 euro and 34,999 then get 4% of [Final] column
Here is the syntax I have so far
CASE WHEN ([Part of Group ?]!="") AND ([ISPG Grouped]="RUBU") THEN [Final] / 100 * 10
WHEN ([Part of Group ?]!="") AND ([ISPG Grouped]="CABU") THEN [Final] / 100 * 10
WHEN ([Part of Group ?] ="") AND ([ISPG Grouped]="RUBU") AND [Final] <> 10000 34999 THEN [Final] / 100 * 4
ELSE NULL END
The error is happening after 34,999 see Pic 1 below for more details
Basically I don't know how to do the If In between two values then execute function :-)
Pic 1:

"... the value of [Final] column is between 10,000 euro and 34,999 ..."
Could you change that part of your formula to this:
... AND [Final] > 10000 AND [Final] < 34999 THEN ...
If you want it to be inclusive, either change the operators to <= and >= or increment the numbers down and up 1 respectively.

Mark P's answer will address the syntax error, but you have a flaw in your CASE logic. CASE expressions will exit once a condition is met. It doesn't check the rest of the conditions, so the order of your conditions matter here.
The first line: WHEN ([Part of Group ?]!="") AND ([ISPG Grouped]="RUBU") THEN will cause the last line to NEVER be evaluated because it contains the same minimal conditions and would exit. To fix this, swap them.
CASE
WHEN ([Part of Group ?]!="") AND ([ISPG Grouped]="CABU") THEN [Final] / 100 * 10
WHEN ([Part of Group ?] ="") AND ([ISPG Grouped]="RUBU") AND [Final] > 10000 AND [Final] < 34999 THEN [Final] / 100 * 4
WHEN ([Part of Group ?]!="") AND ([ISPG Grouped]="RUBU") THEN [Final] / 100 * 10
ELSE NULL END
As you can see here, the second condition is more restrictive than the third thus some cases would fail here, but evaluate to true for the third case.
If you put when 1=1 then 1 at the top of your CASE expression, then the only value you'd ever see is 1. Similarly, if you placed it last... this would be equivalent to saying ELSE 1 since 1 always equals 1, on earth :)

Related

Calculation of average based on a weighted score

I'm trying to calculate an average score based on a list of parameter scores (between 0 and 5). The trick is that I want to be able to weight each parameter.
Eg:
Parameter A Parameter B Parameter C
Weight 100% 70% 0%
Score 4 5 0
In the above example, the average score should be 3,75 as parameter c is left out.
I've tried with this formula: =IF.ERROR(SUM((A3*A5);(B3*B5);(C3*C5))/COUNTA(A3:C3);""). The formula seems to work if none of the parameters weight is equal to 0. How can I adjust the formula, so it excludes a score if weight is equal to zero?
I think it should be rather easy, I just can't get it to work.
Check this :
=SUMPRODUCT( A2:A4, B2:B4 ) / SUM( B2:B4 )
Source : https://exceljet.net/formula/weighted-average
With COUNTA you are counting the non empty cells, while you should count the non zero cells. So, assuming that the weights are in A3:C3 and the scores in A5:C5:
=IFERROR(SUMPRODUCT(A3:C3;A5*C5)/COUNTIF(A3:C3;">0");"Error: all the weigths are 0")
It would be like this:
(1*4 + 0.7*5) / 2 = 3.75
In other world the formula is:
((WeightA/100 * scoreA) + (WeightB/100 * scoreB) + (WeightC/100 * scoreC)) / 3
=SUMPRODUCT(A1:A3;B1:B3) / COUNTIF(B1:B3;"<>0") / 100
Something like this would work

Excel formula for greater than but less than with several tiers

I have a few hundred rows of data, and each has a number between 1 and 200, and I'd like to put them in categories of 1-5 depending on where that number is.
The categories look like this:
Zones Min Max
1 0 35
2 35 60
3 60 85
4 85 110
5 110 200
I want to assign it a Zone if it is greater than the Min, but less than the Max.
I have 2 formulas I've been working with to solve it. One is a nested IF AND statement:
=IF(A1<=35,1,IF(AND(A1<=60,A1>35),2,IF(AND(A1<=85,A1>60),3,IF(AND(A1<=110,A1>85),4,IF(AND(A1<=200,A1>110),2,"TOO BIG")))))
The 2nd formula attempts to use a SUMPRODUCT function:
=INDEX($C$2:$C$6,SUMPRODUCT(--(A1<=$E$2:$E$6),-- (A1>$D2:$D$6),ROW($2:$6)))
Rather than have to continue to adjust the numeric values manually, I set them as absolutes, which is why this formula is slightly different. The E column is the Max value set, and the D is the Min value set.
Any help would be appreciated!
Use this:
=MATCH(A1,{0,35,60,85,110})
Another way is to use VLOOKUP and you just need to set the min number:
=VLOOKUP(D2,$A$2:$B$6,2,1)
The key is the 4th parameter needs to set to 1 which means TRUE. It will find the closest value and return the zone for you.
But noticed that you have overlaps like 35 or 60 etc. that you will need to adjust your value column.

Best method to calculate provision from a table with provision levels?

I have a table with provision levels.
Sales Provision
0 5%
20 000 22%
100 000 30%
A salesman has 5% provision on the first 20 000, 22% on the next 80 000 and 30% on everything above that.
For example a salesman who sells for 230 000 will have provision
=20 000 * 0,05 + 80 000 * 0,22 + 130 000 * 0,30
How can I express this efficiently with a formula? The formula
Needs to be easy to copy to several rows (where a salesman is described by each row)
Needs to work even if I add more provision levels
Well I can say this works (hopefully) for requirement #2:
Needs to work even if I add more provision levels
But note that I am unsure about requirement #1:
Needs to be easy to copy to several rows (where a salesman is described by each row)
Anyway, with this data:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 57600
100000 0.3
I used this formula in E2:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))+(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1)),E1*B1)
If we break this formula down:
The first basic step is to find the index at which the sale value resides. This is the first lower value compared to the sale value. In your example data this is straight forward because the index is the last in the provision list. However to accommodate sale values that fall within the list range we can use:
MATCH(E1,A:A,1)
where E1 is the sale value and A:A is the sale-provision list.
Using this we can incorporate an INDIRECT to get the desired range we need to work with. In this case A1 to A & Index:
INDIRECT("A1:A"&MATCH(E1,A:A,1))
But even within this range we need to figure out two distinct values:
The provision value index lower than our sale value (i.e. 20 000 * 0.05 + 80 000 * 0.22)
The rest of the provision sale value (i.e. 130 000 * 0.30)
So to get the first value we need to set up an array like this:
(20000 - 0) * 0.05 = 20000*.05 = 1000
(100000 - 20000) * 0.22 = 80000*.22 = 17600
SUM = 18600
That can be done by using
(A2:A3 - A1:A2)*(B1:B2)
But to put that in our INDIRECT formula, that would look like
INDIRECT("A2:A"&MATCH(E1,A:A,1)) <- A2:A3
INDIRECT("A1:A"&MATCH(E1,A:A,1)-1) <- A1:A2
INDIRECT("B1:B"&MATCH(E1,A:A,1)-1) <- B1:B2
(INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Just surround that with a SUMPRODUCT to get the total:
SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Then the second value is just the total sale value subtracted by our index value and multiplied by the corresponding provision rate. So that would be:
(E1-A3)*B3
We actually don't need INDIRECT here, a couple INDEX - MATCH lookups will do:
E1 <- E1
INDEX(A:A,MATCH(E1,A:A,1)) <- A3
INDEX(B:B,MATCH(E1,A:A,1)) <- B3
(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1))
Then adding those to formulas together results in the derived formula I showed earlier.
The final addition however was to add an IFERROR wrapper because if the value is less than the first non-zero provision the INDEX-MATCH and INDIRECT will fail. So in the case of an error that means we just need to multiply the sale value by the first provision rate:
E1*B1
And of course if you add an additional provision row:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 63600
100000 0.30
200000 0.50
Or change the provision:
A B C D E
------------------------------------------
0 0.05 Value 22000
20000 0.22 Total Provision 1440
100000 0.30
The formula will index to the proper provision and calculate it properly.
Also,
Since I know I use commas and decimals in my locale and I realized you don't here is the formula for semi-colon list separator:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1;A:A;1))-INDIRECT("A1:A"&MATCH(E1;A:A;1)-1))*INDIRECT("B1:B"&MATCH(E1;A:A;1)-1))+(E1-INDEX(A:A;MATCH(E1;A:A;1)))*INDEX(B:B;MATCH(E1;A:A;1));E1*B1)

percent_rank special case to not include the value being evaluated in the range of group to be evaluated

Consider these values:
company_ID 3yr_value
1 10
2 20
3 30
4 40
5 50
I have this statement on my query and my goal is to compute for the percent rank of value 50 in the group
round(((percent_rank() over (partition by bb.company_id order by bb.3yr_value)) * 100))
in excel, this is equivalent to
=percentrank(b1:b5,b5)
BUT, what I need is an equivalent to this 1:=percentrank(b1:b4,b5) -- notice that I don't include A5 in the range that needs to be evaluated. I'm out of options, and already consulted Mr. Google but it seems I still cant find the solution. I always end up including B5 in my query.
I'm using postgres sql

How do I create a formula for "if x ≥ then multiply by y" and so on?

I've only used Excel for the basics.
I want to multiply the contents of the cell by a different number depending on the value in the cell. I have these ranges:
0 - 499, then multiply by 0
500 - 999, then multiply by 1
1000 - 1499, then multiply by 4
I was able to figure out the formula =IF(C21>=10000,C21*1) for if a value in cell C21 is greater than or equal to 10,000, but I don't see how to extend that to multiple ranges.
How can I write a formula to handle the multiple ranges I've listed above?
You can use another IF in the ELSE part of the expression, evaluation will stop as soon as a TRUE condition is met;
=A1 * IF(A1 < 500, 0, IF(A1 < 1000, 1, IF(A1 < 1500, 4, 0)))
(The last 0 is the case when the value is > 1499)
You can use nested IF statements for doing ranges:
=IF(C21>=500,IF(C21>=1000,IF(C21<1500,C21*4,'dontknowwhatyouwanthere'),C21*1),0)
How about nested Ifs?
=IF(A1<1000;IF(A1<500;+A1*0;+A1*1);+A1*4)
Then you've got:
If it's less than 1000 another if:
If it's less than 500 You do the " * 0 "
If it's not (you are at 500-999 range, from the first if) You do the " * 1 "
Else it's not less than 1000:
You have your " * 4 "
I used this formula and it worked:
=V4*IF(V4<600,0.2,IF(V4<800,0.22,IF(V4<1000,0.25,IF(V4<10000,0.27))))

Resources