I have two cloumns in ssrs
1. Column10
Expression(column1 + column2 + column 3)
2. Column11
Expression(column4 + column5 + column 6)
Now I want to subtract column 11 from column 10
I am doing now
=(Fields!column1.Value) + (Fields!column2.Value) +
(Fields!column3.Value)
-
(Fields!column4.Value) + (Fields!column5.Value) +
(Fields!column6.Value)
Is there any wrong with this approach. Any other better way to do this.
Your expression is incorrect. It is only subtracting Columnr4 - you need to use parenthesis around the entire part that is being subtracted.
=(Fields!column1.Value + Fields!column2.Value + Fields!column3.Value)
-
(Fields!column4.Value + Fields!column5.Value + Fields!column6.Value)
I try to use as few parenthesis as possible to avoid errors like this.
I don't like using Report Items. You could create two calculated fields in the dataset - one for the Column 10 and one for Column 11 that has the expression for each.
Column 10:
=(Fields!column1.Value + Fields!column2.Value + Fields!column3.Value)
Column 11:
=(Fields!column4.Value + Fields!column5.Value + Fields!column6.Value)
Then your expression for Column 12 would be
=Fields!column10.Value - Fields!column11.Value
=Me.ReportItems("txtColumn11").Value - Me.ReportItems("txtColumn10").Value
In the double quotes, is the name of the textbox.
When it's possible, I prefer doing most calculations in the query so there is less business logic in the report expressions.
Related
here is my query
SELECT max_cet_percentage,agri_wg_total, (max_cet_percentage + agri_wg_total) as final_val
FROM agri_table_name_before_weghtage_reupdate
WHERE ApplicationNo LIKE '%30023'
and it's returning the result like this: 36.840515100000005
expected result: 36.8405151
Use truncate to specify number of digits:
SELECT max_cet_percentage,agri_wg_total, truncate(max_cet_percentage + agri_wg_total, 7) as final_val
FROM agri_table_name_before_weghtage_reupdate
WHERE ApplicationNo LIKE '%30023'
Or you could use round(), ceil() or floor() if you want it to adjust the last digit.
Alternatively change the double column to have less digits after decimal:
Alter table tablename modify doubleColumn decimal(14, 7);
Use Truncate
SELECT max_cet_percentage,agri_wg_total, truncate((max_cet_percentage + agri_wg_total), 7) as final_val
FROM agri_table_name_before_weghtage_reupdate
WHERE ApplicationNo LIKE '%30023'
Remove first 3 letters from column Year.
Table name = Register
Column name = Year
Sample:
Year
12/2014
05/1995
Solution would be:
2014
1995
How to make it ? Currently my code is:
SELECT * FROM Register WHERE Year...
One method is to use substr():
select substr(year, 4)
However, I might be inclined to use substring_index():
select substring_index(year, '/', -1)
Note: In both these cases, the returned value is a string. If you want this to be a number, you can include + 0.
Hey is there any way to create query with simple formula ?
I have a table data with two columns value_one and value_two both are decimal values. I want to select this rows where difference between value_one and value_two is grater then 5. How can i do this?
Can i do something like this ?
SELECT * FROM data WHERE (MAX(value_one, value_two) - MIN(value_one, value_two)) > 5
Example values
value_one, value_two
1,6
9,3
2,3
3,2
so analogical difs are: 5, 6, 1, 1 so the selected row would be only first and second.
Consider an example where smaller number is subtracted with a bigger number:
2 - 5 = -3
So, the result is a difference of two numbers with a negation sign.
Now, consider the reverse scenario, when bigger number is subtracted with the smaller number:
5 - 2 = 3
Pretty simple right.
Basically, the difference of two number remains same, if you just ignore the sign. This is in other words called absolute value of a number.
Now, the question arises how to find the absolute value in MySQL?
Answer to this is the built-in method of MySQL i.e. abs() function which returns an absolute value of a number.
ABS(X):
Returns the absolute value of X.
mysql> SELECT ABS(2);
-> 2
mysql> SELECT ABS(-32);
-> 32
Therefore, without worrying about finding min and max number, we can directly focus on the difference of two numbers and then, retrieving the absolute value of the result. Finally, check if it is greater than 5.
So, the final query becomes:
SELECT *
FROM data
WHERE abs(value_one - value_two) > 5;
You can also do complex operations once the absolute value is calculated like adding or dividing with the third value. Check the code below:
SELECT *
FROM
data
WHERE
(abs(value_one - value_two) / value_three) + value_four > 5;
You can also add multiple conditions using logical operators like AND, OR, NOT to do so. Click here for logical operators.
SELECT *
FROM
data
WHERE
((abs(value_one - value_two) / value_three) + value_four > 5)
AND (value_five != 0);
Here is the link with various functions available in MySQL:
https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html
No, you would just use a simple where clause:
select *
from data
where abs(value_one - value_two) > 5;
Here is my mysql query
SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');
Now i want to calculate a value (SUM(QueueTime)+SUM(RingTime))/SUM(AnsweredCalls)
So i modified my query accordingly as below
SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum,IFNULL(SUM(QueueTime),0) + IFNULL(SUM(RingTime),0)/IFNULL(SUM(AnsweredCalls),0)
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');
But when executed it isn't giving me the correct answer.
For example one of the rows returned by this query
QTS RTS AnsweredCallSum CalculatedField
188000 41645 9 192627.222
But the CalculatedField is wrong it should be 25516.11 as per the calculation mentioned above
If SUM(AnsweredCalls) is 0, you are dividing by 0 and it should not work.
This would be my guess:
use IFNULL(..., 1) so you're never dividing by 0 should a null column exist.
Explicitly use parenthesis so order of operations doesn't fail. (You're currently performing sum1 + (sum2 / sum3) when I think you wanted (sum1 + sum2) / sum3). Remember multiplication & division come before addition & subtraction without the parenthesis.
( IFNULL(SUM(QueueTime), 0) + IFNULL(SUM(RingTime), 0) )
/ IFNULL(SUM(AnsweredCalls), 1)
I can't quite figure this out. Microsoft Access 2000, on the report total section I have totals for three columns that are just numbers. These =Sum[(ThisColumn1)], 2, 3, etc and those grand totls all work fine.
I want to have another column that says =Sum([ThisColumn1])+Sum([ThisColumn2]) + Sum([ThisColumn3]) but can't figure those one out. Just get a blank so I am sure there is an error.
Give the 3 Grand Totals meaningful Control Names and then for the Grand Grand Total use:
=[GrandTotal1] + [GrandTotal2] + [GrandTotal3]
Your Grand Total formulas should be something like:
=Sum(Nz([ThisColumn1], 0))
NULL values propagate through an expression which means that if any of your three subtotals are blank, the final total will also be blank. For example:
NULL + 10 = NULL
Access has a built in function that you can use to convert NULL values to zero.
NZ( FieldName, ValueIfNull )
You can use NZ in reports, queries, forms and VBA.
So the example above could read like this:
=NZ([GrandTotal1],0) + NZ([GrandTotal2],0) + NZ([GrandTotal3],0)
http://office.microsoft.com/en-us/access/HA012288901033.aspx
Create a new query, and the sql should look like this:
SELECT SUM(Column1 + Column2 + Column3),
SUM(Column1),
SUM(Column2),
SUM(Column3),
FROM Your_Table;