Month wise cumulative total in column - reporting-services

I need cumulative aggregate after each column for my report. I have a dataset with following data samples.
ProductName *Transdate* Quantity
A 21-Nov-13 100
A 1-Nov-13 50
A 1-Dec-13 40
A 1-Jan-13 150
B 11-Nov-13 30
B 2-Dec-13 20
B 13-Dec-13 10
B 12-Jan-13 80
I want a report which look like below. That means Product wise each month total and Cumulative total. I am able to get month wise total value. Only need suggestion for month wise cumulative total.
**
Product Nov'13 Cumulative Total Dec'13 Cumulative Total Jan'13 Cumulative Total
**
A 150 150 40 190 150 340
B 30 30 30 60 80 140

In the proper textbox use RunningValue function: =RunningValue(Fields!Quantity.Value,SUM,"Category1"):
And your report will display values as follows:

Related

Using outer Group Totals to calculate inner Group Percentages in SSRS 2008R2

I am working on a UK Profit and Loss Report in SSRS 2008R2 and am struggling with the percentage calculations
Here is an example to explain my question
Detail
Group1 Group2 Invoice Number Value %
Sales Total 810
Uk Sales 150
UK964423 50
UK452872 100
European Sales 450
dkkmalk 200
dkf682 250
Rest of World Sales 210
USA12353 100
CHIN25410 100
AFGAN14422 10
Variable Costs 455 56%
Material 200 25%
Sand 150
Steel 50
Wages 225 28%
Basic Pay 175
Overtime 50
Other Production Costs 30 4%
Packaging 20
Consumables 10
The percentage of 56% for the Variable costs is calculated as Variable Costs divided by Sales total (455/810). The Material percentage is similar Material total divided by Total Sales (200/810) and so on for Wages and Other Production Costs
How do I achieve these calculations please. In most cases I can get the nominator by such a formula in the group header as:
=sum(iif (GroupFieldName.Value="Variable Costs",FieldValue.Value,nothing)
But the denominator of Total Sales I can not seem to calculate!
Any suggestions welcome please, please bear in mind I would want to "future proof" the formulas / code solutions for SSRS2015 and SSRS 2017
Thanks in advance
Your expression isn't working correctly due to the grouping. The grouping separates your FieldValues so your SUM is only getting the total of the group.
The expression should use the SUM of your field for the group divided by all the values in your dataset.
=SUM(Fields!FieldValue.Value) / SUM(Fields!FieldValue.Value, "Dataset1")
Due to SSRS checking for divide by zero error, you might need to check for that possibility.
=IIF(SUM(Fields!FieldValue.Value, "Dataset1") = 0, 0, SUM(Fields!FieldValue.Value) )
/
IIF(SUM(Fields!FieldValue.Value, "Dataset1") = 0, 1, SUM(Fields!FieldValue.Value, "Dataset1")
With the IIFs, if the SUM is 0 the calculation is 0/1 which is 0 and avoids the Divide by Zero error.

mysql - get the average of the output average

I have 3 table. final,milestone and milestonewp consider that the three tables is foreigned key like milestonewp<--FK--milestone<--FK--Final .Then I have a column for determining the average of the milestonewp for a certain foreign key. Then getting that average to be average again to be displayed to the final table.Here is my visual representation
milestonewp
condition | mile_id
20 1
20 1
30 1
21 2
21 2
31 2
40 3
30 3
50 3
How can I average the average that the chart above will produce?
I'm trying to work on this
select avg(milewp_condition)
from logs_pms_r_milestone_wp
where mile_id=1;
but i dont have any idea how it can produce for the other mile_id
EDIT
The above code will produce something like this
avg(milewp_condition)
0
0
0
so then, i also want to average that 3 rows.
If I understand well this should be what you look for:
SELECT AVG(milewp_condition)
FROM logs_pms_r_milestone_wp
GROUP BY mile_id;
If you want to average all, just do:
SELECT AVG(milewp_condition)
FROM logs_pms_r_milestone_wp;
Regards

How to query specific rows order by multiply result

I have a product table with commission column. I want to compare the product and sort by commission result. Is it possible to do so? Here I have :
id price com% (com)
3 3500 23 (805)
4 3800 23 (874)
30 3800 25 (950)
31 4000 25 (1000)
32 3500 22 (770)
According to the com column. I expect the result to sort from 31,30,4,3 and 1 accordingly. All I can thinking of is this query.
select * from excursion_db order by exc_com desc
Only sort by the commission (com column). Which may cause an error when there's a high com% but low price. Eventually the com might lower than the higher price but less com%.
So, how to get the specify row order by the sum of price*com% desc?
Please note that : The (com) column is not exists in the table. I write up here to compare the total commission.
Try this:
select * from excursion_db order by price * `com%` desc

SSRS sum grouping

I'm trying to create a report
Order Revenue SUM
1 100
2 200
Total=300
3 100
4 400
5 500
6 200
Grand Total = 1500
Here I want sum of the first 2 rows and grand total in the end. What should I write in the expression cell in row group?
You can use Running Value.
=RunningValue(Fields!Revenue.Value, Sum, Nothing)
https://technet.microsoft.com/en-us/library/ms159136(v=sql.100).aspx

Grouping Data in MS Access 2010 based on multiplication

I am a new user to MS Access.
My table has 2 columns: a column for number of days which goes from 0 to 150+ and a column for principal paid (any number say 858576)
There are over 70000 rows.
Row 1 says 70 days and principal paid as 898956
Row 2 says 68 days and principal paid as 13751
Row 3 says 190 days and principal paid as 397159
Row 4 says 11 days and principal paid as 56978
Row 5 says 29 days and principal paid as 9078910
I want a query to return records from 0-30 days, 30-60 days, 60-90 days, 90-120 days, 120-150 days and 150 above and showing sum of principal against each group mentioned above. Can it be done? If so, how?
If you know the maximum number of your days in the table and criteria for dividing into groups, you could try by using the case:
SELECT
SUM(principal_paid),
days_range
FROM
(
SELECT
principal_paid,
CASE days
WHEN BETWEEN 0 AND 30
THEN '0-30'
WHEN BETWEEN 31 AND 60
THEN '31-60'
WHEN BETWEEN 61 AND 90
THEN '61-90'
WHEN BETWEEN 91 AND 120
THEN '91-120'
WHEN BETWEEN 121 AND 150
THEN '121-150'
ELSE 'over 150'
END AS days_range
FROM
yourtable
)
as T
GROUP BY
days_range