Hi I have a table column named "sku" which of type integer and another column "total_sku" which again is of type integer , when I'm trying to calculate the percentage(100 * sku/total_sku) using Calculator step. I'm expecting an integer but its giving me 0.00 , kindly help
Thanks in advance.
sku total_sku percentage
23 2115 1.087
40 2115 1.891
My guess is that the calculator is doing the division before the multiplication, computing 100*(A/B), rather than (100*A)/B. Since you are dealing with integers, it is rounding A/B down to zero, and that is the end of it for you.
The calculator step lets you break a calculation down into multiple smaller components, all within the step. You can even specify which fields created in those substeps should stay in the stream, and which should are temporary values that should be discarded.
So try first doing a calculation such as tempValue = 100*A, then result = tempValue/B. Set Value type to Integer in both steps.
In the Calculator step, put 'Value type' as 'Integer'
Related
I've been learning TSQL and need some help with a conversion CPU MIPS into PERCENTAGE.
I've built my code to get some data that I'm expecting. In addition to this, I want to add a column to my code which is to get the CPU%. I have a column that gives me TOTALCPU MIPS and want to use this in the code but in the form of percentage. Example, I have these values in my TOTAL CPU Column:
1623453.66897
0
0
2148441.01573933
3048946.946314
I want to convert these values into percentage and use them. I couldn't find much info on the internet.
Appreciate your response.
I assume that you have 5 numeric quantities (2 of them being zero) and you want to find the percentage that corresponds to each of them out of the addition of the five quantities. Is it so?
To find the percentage of a particular number in the addition you multiply the number by 100 and divide by the addition, the result is the percentage that that number is in relation with the addition.
The sum: 6820841.631023
The percentage of the first number (of MIPS):
1623453.668970 * 100 / 6820841.631023 = 23.80136876 =>
23.80136876% is the percentage of CPU used by the first program.
To give the answer some SQL looking, refering to Mips_Table as the view/table that contains the MIPs data:
select mips, mips/totMips*100 Pct_CPU
from Mips_Table,
(select sum(mips) TotMips from Mips_Table) k
I am working on pentaho report designer
HereI created one cross tab report. When I preview the report it is showing me results as below
name total
A 598.00
B 273.00
c 124.00
d 0.23
e 0.23
f 0.00
g 273.00
In the above results I want only the particular values should look in decimal format
Like I want only o.23 in the above result look like in decimal format and all the other I want to look like integer with out any decimal portions.
Is there any expression I can write.
Thanks in advance
In Pentaho report designer, you must define a data type for your inputs(https://www.screencast.com/t/y440gotpnp). The case that you describe could be treated with a formula(check the floating numbers e.g. different to "00" ... ) and as an output data type you could use a string(text)
Maybe you should use Truncate function inside you query, something like truncate(total,2), this will keep 2 digits after the ',' and if your totals end with 00 they won't be shown automatically.
All,
I'm running the SQL query below in MS Access 2010. Everything works fine except that the "a.trans_amt" column is rounded to a whole number (i.e. the query returns 12.00 instead of 12.15 or 96.00 instead of 96.30). Any ideas? I'd like it to display 2 decimal points. I tried using the ROUND function but didn't have any success.
Thanks!
INSERT INTO [2-Matched Activity] ( dbs_eff_date, batch_id_r1, jrnl_name,
ledger, entity_id_s1, account_s2, intercompany_s6, trans_amt,
dbs_description, icb_name, fdt_key, combo )
SELECT a.dbs_eff_date,
a.batch_id_r1,
a.jrnl_name,
a.ledger,
a.entity_id_s1,
a.account_s2,
a.intercompany_s6,
a.trans_amt,
a.dbs_description,
a.icb_name,
a.fdt_key,
a.combo
FROM [1-ICB Daily Activity] AS a
INNER JOIN
(
SELECT
b.dbs_eff_date,
b.batch_id_r1,
b.jrnl_name,
sum(b.trans_amt) AS ["trans_amt"],
b.icb_name
FROM [1-ICB Daily Activity] AS b
GROUP BY dbs_eff_date, batch_id_r1, jrnl_name, icb_name
HAVING sum(trans_amt) = 0
) AS b
ON (a.dbs_eff_date = b.dbs_eff_date) AND (a.batch_id_r1 = b.batch_id_r1) AND
(a.jrnl_name = b.jrnl_name) AND (a.icb_name = b.icb_name);
Essentially, you are attempting to append decimal precise values to an integer column. While MS Access does not raise a type exception it will implicitly reduce precision to fit the destination storage. To avoid these undesired results, set the precision type ahead of time.
According to MSDN docs, the MS Access database engine maintains the following numeric types:
REAL 4 bytes A single-precision floating-point value with a range of ...
FLOAT 8 bytes A double-precision floating-point value with a range of ...
SMALLINT 2 bytes A short integer between – 32,768 and 32,767.
INTEGER 4 bytes A long integer between – 2,147,483,648 and 2,147,483,647.
DECIMAL 17 bytes An exact numeric data type that holds values ...
And the MS Access GUI translates these as Field Sizes in table design interface where the default format of Number is Long Integer type.
Byte — For integers that range from 0 to 255. Storage requirement is a single byte.
Integer — For integers that range from -32,768 to +32,767. Storage requirement is two bytes.
Long Integer — For integers that range from -2,147,483,648 to +2,147,483,647 ...
Single — For numeric floating point values that range from -3.4 x 1038 to ...
Double — For numeric floating point values that range from -1.797 x 10308 to ...
Replication ID — For storing a GUID that is required for replication...
Decimal — For numeric values that range from -9.999... x 1027 to +9.999...
Therefore, in designing your database, schema, and tables, select the appropriate values to accommodate your needed precision. If not using the MS Access GUI program, you can define type in a DDL command:
CREATE TABLE [2-Matched Activity] (
...
trans_amt DOUBLE,
...
)
If table already exists consider altering design with another DDL command.
ALTER TABLE [2-Matched Activity] ALTER COLUMN trans_amt DOUBLE
Do note: if you run CREATE and ALTER commands in Query Design window, no prompts or confirmation will occur but changes will render.
I have this TypeError as per below, I have checked my df and it all contains numbers only, can this be caused when I converted to numpy array? After the conversion the array has items like
[Timestamp('1993-02-11 00:00:00') 28.1216 28.3374 ...]
Any suggestion how to solve this, please?
df:
Date Open High Low Close Volume
9 1993-02-11 28.1216 28.3374 28.1216 28.2197 19500
10 1993-02-12 28.1804 28.1804 28.0038 28.0038 42500
11 1993-02-16 27.9253 27.9253 27.2581 27.2974 374800
12 1993-02-17 27.2974 27.3366 27.1796 27.2777 210900
X = np.array(df.drop(['High'], 1))
X = preprocessing.scale(X)
TypeError: float() argument must be a string or a number
While you're saying that your dataframe "all contains numbers only", you also note that the first column consists of datetime objects. The error is telling you that preprocessing.scale only wants to work with float values.
The real question, however, is what you expect to happen to begin with. preprocessing.scale centers values on the mean and normalizes the variance. This is such that measured quantities are all represented on roughly the same footing. Now, your first column tells you what dates your data correspond to, while the rest of the columns are numeric data themselves. Why would you want to normalize the dates? How would you normalize the dates?
Semantically speaking, I believe you should leave your dates alone. Whatever post-processing you're planning to perform on your numerical data, the normalized data should still be parameterized by the original dates. If you want to process your dates too, you need to come up with an explicit way to handle your dates to something numeric (say, elapsed time from a given date in given units).
So I believe you should drop your dates from your processing round altogether, and start with
X = df.drop(['Date','High'], 1).as_matrix()
I am writing a custom totaling method for a grid view. I am totaling fairly large numbers so I'd like to use a decimal to get the total. The problem is I need to control the maximum length of the total number. To solve this problem I started using float but it doesn't seem to support large enough numbers, I get this in the totals column(1.551538E+07). So is there some formating string I can use in .ToString() to guarentee that I never get more then X characters in the total field? Keep in mind I'm totaling integers and decimals.
If you're fine with all numbers displaying in scientific notation, you could go with "E[numberOfDecimalPlaces]" as your format string.
For example, if you want to cap your strings at, say, 12 characters, then, accounting for the one character for the decimal point and five characters needed to display the exponential part, you could do:
Function FormatDecimal(ByVal value As Decimal) As String
If value >= 0D Then
Return value.ToString("E5")
Else
' negative sign eats up another character '
Return value.ToString("E4")
End If
End Function
Here's a simple demo of this function:
Dim d(5) As Decimal
d(0) = 1.203D
d(1) = 0D
d(2) = 1231234789.432412341239873D
d(3) = 33.3218403820498320498320498234D
d(4) = -0.314453908342094D
d(5) = 000032131231285432940D
For Each value As Decimal in d
Console.WriteLine(FormatDecimal(value))
Next
Output:
1.20300E+000
0.00000E+000
1.23123E+009
3.33218E+001
-3.1445E-001
3.21312E+016
You could use Decimal.Round, but I don't understand the exact question, it sounds like you're saying that if the total adds up to 12345.67, you might only want to show 4 digits and would then show 2345 or do you just mean that you want to remove the decimals?