Calc with format number - numbers

I am having a problem in formatting numbers. I am getting a string concatenation instead of the numerical sum.
I have attached the screenshot of the problem.
Help me please. Thanks.
https://drive.google.com/open?id=1vv5doL2QByU_54kPDoKFRvqj6aaSRxbg
https://drive.google.com/open?id=1-BktFl_j9H3tzKGysDoDlr4nB7cDVEGu
I need the sum of 5 + 5 + 5, but the result is 555 instead of 15.
Thanks

When you join the Number array it will be converted a string. Please update as below
var total = #All of Suma OD.reduce(function(a, b) { return a + b; }, 0);
total - [Your other calculation logics]

Related

Tableau : Calculed field to transform series of odd numbers to a sequence of numbers

I need your help with the formulation for a calculed a field in Tableau (Tableau Prep to be accurate).
I have a field called [Code Order] which contains only a series of Odd numbers (1,3,5,7,9,..) multiple times, which means it can be (1,3,1,3,5,7,1,1,1,3,5,7,9,11).
What I need is to transform these in a normal sequence of numbers so for my example above I need as a result: (1,2,1,2,3,4,1,1,1,2,3,4,5,6)
In other words when in [Code Order] I have :
1 = 1
3 = 2
5 = 3
7 = 4
9 = 5
11 = 6
13 = 7
15 = 8
...
365 = 183
For the moment my maximum is 365, which is position 183, I would like to avoid to type 182 IF formulas if possible. ;)
Thanks in advance for your help.
CYA
Plt.K
This might turn out to be more accurate in case your Code Order series is missing any values along the way.
Example series:
Alternate Field:
Tableau Setup:
You want to use the index() calculated field. Create a new field called index. The calculation is just index().
Add [Code Order] to your row shelf and index to your label. You should see something like this.
The following calculation should do the trick
CEILING([Code Order] / 2)

sum two values from different datasets using lookups in report builder

I have a report that should read values from 2 dataset by Currency:
Dataset1: Production Total
Dataset2: Net Total
Ive tried to use:
Lookup(Fields!Currency_Type.Value,
Fields!Currency_Type1.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
This returns only the first amount from dataset 2.
I've tried Lookupset function as well but it didn't SUM the retrieved values.
Any help would be appreciated.
Thanks Jamie for the reply.
THis is what i have done and it worked perfect:
From Report Properties--> Code , write the below function:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
If (ct = 0) Then return 0 else return suma
End Function
Then you can call the function:
code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))
Yes, Lookup will only return the first matching value. Three options come to mind:
Change your query, so that you only need to get one value: use a GROUP BY and SUM(...) to combine your two rows in the query. If you are using this query other places, then make a copy and change that.
Is there some difference in the rows? Such as one is for last year and one is for this year? If so, create an artificial lookup key and lookup the two values separately:
=Lookup(Fields!Currency_Type.Value & ","
& YEAR(DATEADD(DateInterval.Year,-1,today())),
Fields!Currency_Type1.Value & ","
& Fields!Year.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
+
Lookup(Fields!Currency_Type.Value & ","
& YEAR(today()),
Fields!Currency_Type1.Value & ","
& Fields!Year.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
Use the LookupSet function as mentioned. With this you'll get a collection of the values back, and then need to add those together. The easiest way to do this is with embedded code in the report. Add this function to the report's code:
Function AddList(ByVal items As Object()) As Double
If items Is Nothing Then
Return 0
End If
Dim Total as Double
Total = 0
For Each item As Object In items
Total = Total + CDbl(item)
Next
Return Total
End Function
Now call that with:
=Code.AddList(LookupSet(Fields!Currency_Type.Value,
Fields!Currency_Type1.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2"))
(Note: this code was not tested. I just composed it in the Stack Overflow edit window & I'm no fan of VB. But it should give you a good idea of what to do.)

iPhone Converting ISBN13 to ISBN10

I'm trying to program it such that it would calculate the check digit of isbn 10 from isbn 13. Can anyone give some advice on how to carry it out?
Firstly, how do i actually loop through a 13 digit isbn, remove the prefixed 978 in front before i proceed on to calculate the check digit of the isbn10? Thank you in advance!:)
This is how you can remove the first 3 digits:
NSString *str = #"978XXXXXXXXX";
NSString *newStr = [str substringFromIndex:3];
And as for your ISBN10:
The final character of a ten digit International Standard Book Number is a check digit computed so that multiplying each digit by its position in the number (counting from the right) and taking the sum of these products modulo 11 is 0. The digit the farthest to the right (which is multiplied by 1) is the check digit, chosen to make the sum correct. It may need to have the value 10, which is represented as the letter X. For example, take the ISBN 0-201-53082-1. The sum of products is 0×10 + 2×9 + 0×8 + 1×7 + 5×6 + 3×5 + 0×4 + 8×3 + 2×2 + 1×1 = 99 ≡ 0 modulo 11. So the ISBN is valid.
While this may seem more complicated than the first scheme, it can be validated simply by adding all the products together then dividing by 11. The sum can be computed without any multiplications by initializing two variables, t and sum, to 0 and repeatedly performing t = t + digit; sum = sum + t; (which can be expressed in C as sum += t += digit;). If the final sum is a multiple of 11, the ISBN is valid.
Taken from here.

Getting the first decimal place of a number

I have a number for example: 2.4444444. I need to get first digit after the dot -- in my case it's 4. How to implement it?
How about
( (int)(floor( fabs( num ) * 10 ) ) ) % 10
Chech these out! Tried it for you hope it helps
#include<stdio.h>
int main()
{
int b;
float a;
a=2.4444; 'load some value
b=(int)a; 'typecast it into integer you get 2 into b variable
a=a-b; ' subtract b from a and you will get decimal point value 0.4444
a=a*10; ' multiplying with 10 gives 4.444
b=(int)a; ' now apply the same logic again
printf("%d",b); 'outputs 4
}
Update written these function using these link
Extract decimal part from a floating point number in C
it could be as simple as
num*10%10
(int)(num * 10) - ((int)num) * 10

binary to decimal in objective-c

I want to convert the decimal number 27 into binary such a way that , first the digit 2 is converted and its binary value is placed in an array and then the digit 7 is converted and its binary number is placed in that array. what should I do?
thanks in advance
That's called binary-coded decimal. It's easiest to work right-to-left. Take the value modulo 10 (% operator in C/C++/ObjC) and put it in the array. Then integer-divide the value by 10 (/ operator in C/C++/ObjC). Continue until your value is zero. Then reverse the array if you need most-significant digit first.
If I understand your question correctly, you want to go from 27 to an array that looks like {0010, 0111}.
If you understand how base systems work (specifically the decimal system), this should be simple.
First, you find the remainder of your number when divided by 10. Your number 27 in this case would result with 7.
Then you integer divide your number by 10 and store it back in that variable. Your number 27 would result in 2.
How many times do you do this?
You do this until you have no more digits.
How many digits can you have?
Well, if you think about the number 100, it has 3 digits because the number needs to remember that one 10^2 exists in the number. On the other hand, 99 does not.
The answer to the previous question is 1 + floor of Log base 10 of the input number.
Log of 100 is 2, plus 1 is 3, which equals number of digits.
Log of 99 is a little less than 2, but flooring it is 1, plus 1 is 2.
In java it is like this:
int input = 27;
int number = 0;
int numDigits = Math.floor(Log(10, input)) + 1;
int[] digitArray = new int [numDigits];
for (int i = 0; i < numDigits; i++) {
number = input % 10;
digitArray[numDigits - i - 1] = number;
input = input / 10;
}
return digitArray;
Java doesn't have a Log function that is portable for any base (it has it for base e), but it is trivial to make a function for it.
double Log( double base, double value ) {
return Math.log(value)/Math.log(base);
}
Good luck.