How to add a loop in SSRS - reporting-services

I am using SSRS 2012 R2.
I need to create a loop in ssrs to calculate the compliance of ONB to LB
but with a condition, for the total bags count <= 100 it will be 27 mins. but for each additional 50 bags add 5 mins.
I tried the code below but it takes only 27 and 34 min. I want to replace 34 with a loop.
count(
iif(Fields!Duration_ONB_LB_.Value <
iif(Fields!Total_Bag_Count.Value <= "100", "27","34") ,1, Nothing))
/ count(Fields!TotalRows.Value) * 100 )
Can you please help me out in this?

I'm not sure if 'loop' is the correct term, I assume you want to just create an expression that adds 5 mins for every 50 bags (or part of).
I created a sample dataset so you can see the results, it assumes that up to 100 bags is 27 mins, 101-150 bags would be 32 mins, 151-200 bags would be 37 mins and so on...
here is the expression I used, you will need to replace the iif(Fields!Total_Bag_Count.Value <= "100", "27","34") part of your expression with this.
IIF
(
Fields!Total_Bag_Count.Value <= 100,
27,
(CEILING((Fields!Total_Bag_Count.Value -100) / 50) * 5) + 27
)
Here are the results

Related

How do you group values in SQL Server Report Builder 2014

I am trying to replicate the group function in Excel, through SSR. I have tried grouping in report builder, & the following expression.
=IIF(First(Fields!Age.Value)<21,"Under 21",(IIF(First(Fields!Age.Value)>=21 AND First(Fields!Age.Value)<=50,"Between 21 and 50","Over 50")))
I will actually need a lot more groups than this, but was trialing this out to ensure it works. The principle is good, in regards to it re naming the columns with the corresponding group.. i.e 17>21 fall into Under 21 but I still have 5 rows of data whereas I would like only one row with sum of under 21 etc.
what I am looking for -
Age Count
under21 1
22-30 2
31-40 1
41-50 4
51-60 11
61-70 9
71+ 18
I think what you want are separate columns for each group:
For your Under 21 column, the expression would be:
=SUM(IIF(Fields!Age.Value < 21, 1, 0) )
For 21 - 30, use:
=SUM(IIF(Fields!Age.Value >= 21 AND Fields!Age.Value <= 30, 1, 0) )
And so on. The downside is that you need to create a separate one for each age group. Luckily we don't live too long.
Now that I re-read your question, it looks like you already have it the way you want. Are you just need to use =CountRows() for the number in the group?

calculate two columns in MySQL

I have a MySQL database, where I have 3 columns:
Day_hours
Day_minutes
All_day_hours
I am gonna have some different form fields in a JSP page, where I can put in how many hours I work. On a day I work in different places, that means that I need fx to put in 5 * Day_hours, Day_minutes and All_day_hours. So the problem is that I want to calculate all the hours and minutes during a day. So if I fx worked:
1 job: 2 hours 15 minutes
2 job: 3 hours 45 minutes
3 job: 1 hours 10 minutes
4 job: 4 hours 40 minutes
5 job: 3 hours 15 minutes
So that means if I calculate the column "Day_minutes" it would give me the result 125. I would like that the 125 minutes is converted to hours, so the result would be 2 hours and 5 minutes. Afterwords the Day_hours and Day_minutes have to be addéd to the column Allday_hours. So Allday_hours is the sum of Day_hours + Day_minutes
so Fx in MySQL database there is the following information for an example day:
Day_hours Day_minutes Allday_hours
1 job 2 15 2.15
2 job: 3 45 3.45
3 job: 1 10 1.10
4 job: 4 40 4.40
5 job: 3 15 3.15
So my question is, how do I calculate the Day_hours and Day_minutes to the Allday_hours, so the result in job 1 would be 2.15?
Have a good weekend.
Best Regards
Mads
You should not save something in Allday_hours as this is redundant information.
You can retrieve the data you want always (without problems) from the data you have. For example with
SELECT *, ((Day_hours*60 + Day_minutes)/60) AS Allday_hours FROM timedata...
No need to actually save them.
By the way I think it is rather odd that 2 hours plus 15 minutes add up to something like 2.15. So my query above computes something relative... if you really want to compute your value, you might use
SELECT *, (Day_hours + (Day_minutes / 100)) as Allday_hours FROM timedata
And if you really want to save this, you can use the calculations in an update statement like
UPDATE timedata SET Allday_hours = (Day_hours + (Day_minutes / 100))

google spreadsheet calculation

How to calculate this:
0-10 hours = 100 pr. hour
11-20 hours = 80 pr. hour
21+ hours = 70 pr. hour
If ex. I have 23 hours:
10 hours - 100 pr. hour
10 hours - 80 pr. hour
3 hours - 70 pr. hour
Is it possible to write a function in Google spreadsheet to calculate the total amount if I only have the total hours.
You can express this as a formula. Consider that there are three cases:
If more than 20 hours, rate is (10 x 100 + 10 x 80) + (hours - 20) x 70
If less than 21 hours but more than 10, rate is (10 x 100) + (hours - 10) x 80
If less than 11 hours, rate is hours x 100
If we have our hours in cell A1, here's the formula:
=if(A1>20,(A1-20)*70+1800,if(A1>10,(A1-10)*80+1000,A1*100))
I'm writing gsheet formulas for 4+years.
IMHO you need to create additional table "rates"
HoursFrom | HoursTo | Rate
0 | 10 | 100
11 | 20 | 80
21 | 9999 | 70
than you can write flexible formula that will work everywhere:
= filter(rates!C:C, rates!A:A>A1, rates!B:B
it may seem a bit more complex in the beginning, but late you will easily read your formula and you will be able to change your data in single place in your "Rates" table without searching for all formulas that refer to this data.
Yes, it's possible to write a function for this. Here is a sample code.
function amount(x) {
if(!x){
return "no hours provided";
} else {
if(x<=10){
return x*100;
} else if (x<=20){
return 10*100+(x-10)*80;
} else {
return 10*100+10*80+(x-20)*70;
}
}
}
You can use this anywhere in the spreadsheet as a custom function. e.g. if
A1 = 23;
//You can put below line in any cell. A2 is just being given as an example
A2 = amount(A1) //answer will be 2010

Rails Daily/Monthly Report

Report
I need to create a daily report + monthly report with this records.. All records is from one table and under one field('nature' is the name of my field)..
Calls
Texts
Emails
Is there any possible way to create a single query that will
generate this daily report + monthly report.?
Ex.
Day1 Day2 Day3 etc.. Total
Calls 20 23 23 ... 66
Texts 120 125 130 ... 375
Emails 50 60 55 ... 165
Total 190 208 208 ... 606
If not, please tell how to do it the simplest way, and how to this on rails.?
Thanks in advance...
for One month
$todayDate = date("Y-m-d");
$thismonth = strtotime($todayDate);
$next_month = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));
query
select colum_name from table_name where month(table_field_name) BETWEEN month($thismonth) AND month($next_month) AND year(table_field_name) BETWEEN year($thismonth) AND year($next_month)

What would be the best practice to store multiple 2 digit dataset in MySql server

Let say i want to store several dataset ie
78 94 33 22 14 55 18 10 11
44 59 69 79 39 49 29 19 39
And later on i would like to be able run queries that will determine the frequency of certain number. What would be the best way to this? What would be table structure to make a fast query.
Please be specific as you can be.
To get the counts, you can run a query such as:
SELECT value, COUNT(*) from table_of_values GROUP BY value
Placing an index on the single integer value column is pretty much all you can do to speed that up.
You could of course also just keep a table with every two-digit value and a count. You will have to pre-fill the table with zero counts for every value.
Then increment the count instead of inserting:
UPDATE table_of_values SET count = count + 1 WHERE value = (whatever)