ssrs iif conditional sum based on dense rank - reporting-services

I looked at this thread already but get #Error
SSRS Conditional Summing
Back Story:
I have a ssrs report to qa. Total calls value is going up based on orders value i.e. total calls value repeats if a sales person took 5 orders.
This should not be the case. Example:
left side is wrong right side is correct at employee level in grey.
abc | 500 | order-001
not
abc |500 | order-001
abc |500 | order-002
abc |500 | order-003
So i modified the SP to use Dense rank function.
Now within SSRS
At supervisor level I want to do a sum of total calls
=sum(IIF(Fields!Dense_Rank.Value=1 Or "NULL",Fields!TotalCalls.Value,0))
but this expression is evaluating to #Error at Supervisor level.
Finally, I wish to get a quick fix for this not re-invent the wheel or change the requirements.
Any help would be greatly appreciated.

Assuming Fields!Dense_Rank.Value refers to a column in your dataset called Dense_Rank (naming fields after t-sql functions is not generally advised, as this may lead to confusion), I think what you are trying to achieve is the following:
=sum(
IIF
(
(Fields!Dense_Rank.Value=1 Or Fields!Dense_Rank.Value Is Nothing),
Fields!TotalCalls.Value,
0
)
)

Related

How to sum only one of repeated values from joined data in RDLC

I'm not sure if SSRS is dumb, or I am (I'm leaning towards both).
I have a dataset that (as a result of joins etc) has some columns with the same values duplicated across every row (fairly standard database stuff):
rid cnt bid flg1 flg2
-------------------------------
4 2882 1 17 3
5 2784 1 17 3
6 1293 1 17 3
18 9288 2 4 9
20 762 2 4 9
Reporting based on cnt is straightforward enough. I can also make a tablix that shows the following:
bid flg1 flg2
------------------
1 17 3
2 4 9
(Where the tablix is grouped by Fields!bid.Value and the columns are just Fields!flg1.Value and Fields!flg2.Value respectively.)
What I can't figure out is how to display the sum of these values -- specifically I want to show that the sum of flg1 is 21 and the sum of flg2 is 12 -- not the sum of every row in the dataset (counting each value more than once).
(Note that I'm not looking for a sum of distinct values, as they may not be unique. I want a sum of one value from each bid group, because it's from a table join so they will always have the same value.)
If possible, I'd also like to be able to do a similar calculation at the top level of the report (not in any tablix); although I'd settle for hiding the detail row if that's the only way.
Obviously, Sum(Fields!flg1.Value) isn't the answer, as this either returns 51 (if on the first row inside the group) or 59 (if outside it).
I also tried Sum(Fields!flg1.Value, "bid") but this wasn't considered a valid scope.
I also tried Sum(First(Fields!flg1.Value, "bid")) but apparently you're not allowed to sum first values for some weird reason (and may have had the same scope problem anyway).
Using Sum(Max(Fields!flg1.Value, "bid")) does work, but feels wrong. Is there a better way to do this?
(Related: is there a good way to save the result of that calculation so that I can later also show a Sum of those totals without an even hairier expression?)
There are two basic ways to do this.
Do what you have already done (Sum(Max(Fields!flg1.Value, "bid")))
Sum the rendered values. To do this check the name of the cell containing the data you want (check it's properties) and then use something like =SUM(ReportItems!flg1.Value) where flg1 is the name of the textbox, which is not necessarily always the same name as the field.

Use 2 Datasets inside a Matrix

I'm creating a report that shows how many sq ft my company worked during a time period and what's the cost per sq ft. I have this 2 Datasets
ServiceProviderSqFt
ServiceProviderID
ServiceProviderName
Total
Month
CostSqFt
ServiceProviderID
ServiceProviderName
Cost
So the matrix I created looks like this:
ServiceProvider | Expr(Months) | *Cost Per Sq Foot |
ServiceProvider | Sum(Total) |missing|
So, the word missing is where I'm having problems. I need to put over there the Cost for each provider, so It can looks like this:
Service Provider | Jan | Cost Per Sq Foot
Provider 1 | 250 | 1.10 |
Any thoughts?
Thanks in advanced
If you have to use 2 separate datasets, you can use the Lookup function. There are many resources on that out there. The best option with SSRS is to combine those datasets at the database level as subqueries so that you can work with just the one dataset in the report. Hopefully this points you in the right direction.

SSRS grouping on multiple tablix

I have main report that has around 10 tablix and one sub report that has 2 charts. I want the each tablix grouped by same column, but every table uses different datasets. By using List control, we can group the tablix and set a page break between each group. For that, list dataset and tablix dataset must use the same dataset name.But I am not sure how to do that for multiple datasets. Could anyone please help me how to group multiple tablix based on same field value.Is it possible using list to do that? TIA
Attached for reference
. Each tablix uses different data sets.but the field names are same.If Service_line column has 10 rows, then I want to display in 10 pages(one page per service line).If I select page break at each tablix, first tablix splits by that field name,after that next tablix starts to split by that field name. I want to show A/R,cash,Adjustments in one page per service_line field and then next page the same tables but different service_line. So I thought Put in List all tables together and grouping at List level will solve the problem.Could you please help me on that? or if you have any other suggestions please let me know. I am not sure how to get this done. Appreciate your help.
If I understood you correctly, what you want to do is modify your data a little and use nested grouping.
Combine your datasets into one dataset using unions and label each row with column 'Category'that has value ('A/R', 'Cash', 'Adjustments')
for example your dataset might look something like this
CATEGORY | SERVICE_LINE | Total | ...
-------------------------------------
A/R | A | 100
A/R | B | 10
A/R | C | 1000
Cash | B | 50
Adjustments | B | 100
Cash | A | 5
Cash | C | 400
Adjustments | C | -100
Adjustments | A | 9999
after that you will create a 1 tablix (forget about the lists). And inside that tablix you will create a row group for Category and merge all columns and set value for the cell as [CATEGORY]. Also for this row group you want to set Page Break options as "Between each instance of a group". After that create a row below that contains all the column labels Service_line, Total, etc.
Now what you have to do is create one more row group as Adjacent Below and use Service_Line as group by attribute.
with some UI tweaking you can get it to look as you want.

Find times value has been used and multiply it by amount across tables in SQL

I'm doing a school assignment that has to do with gifts and their production time. We have the table "gift" which contains the name, gift_number and gift_production_time, and the table "wishes", which contains gift_number, wish_number and person_number. With these tables we have to calculate the amount of time it takes for all the gifts to be made in minutes and days rounded up.
Seeing as this is an introductory course to databases, I've hit a roadblock on this task. The closest I can get is to have a row for each gift, showing the production time of each of them individually, but not the total amount of time it takes.
Here is my closest attempt:
SELECT w.gift_number, count(w.gift_number)*production_time as total_minutes
FROM wishes as w, gifts as g
WHERE g.gift_number = w.gift_number
GROUP BY w.gift_number
I don't think I can get the correct answer with the GROUP BY statement, but the math isn't correct if I omit it. Any help would be much appreciated. :-)
EDIT
Gift table
|gift_number | gift_name | production_time
|_________________________________________
|1 gift1 130
|2 gift2 140
|3 gift3 200
|4 gift4 100
Wishes table
|wish_number | person_number | gift_number |
|___________________________________________
|1 1 2
|2 1 4
|3 2 2
|4 3 1
First, if you are learning SQL, you should learn proper join syntax. As a simple rule: Never use commas in the from clause.
Second, the query that you have written is incorrect from the perspective of SQL. MySQL accepts it, but the problem is production_time. It is not in an aggregation function (such as sum() or min()) and it is not in the group by clause. So, you are using a MySQL extension. And, you should only use this extension when you really, really understand what you are doing.
I suspect that the query you want is more like this:
SELECT sum(production_time) as total_minutes
FROM wishes w JOIN
gifts g
ON g.gift_number = w.gift_number;
Depending on how time is represented (an integer number of minutes? as a time? etc.) and how you want to see the results, you may need to use date/time functions. I would suggest you review them here and play with them to get the results you want.

To calculate sum of the fields in a matrix with column grouping

I am working on a ssrs report with column grouping. the followin is my scenario.
Matrix 1:
ID 2012 2013
1 20 40
1 30 50
Total 50 90
Matrix 2:
ID 2012 2013
1 60 70
1 60 80
Total 120 150
I need the sum of matrix1 and matrix2 like below:
ID 2012 2013
1 170 240
But I got the result like :
ID 2012 2013
1 410 410
I have applied column grouping in all the 3 matrices and gave the expression to get sum for matrix 3 as: =Sum(Fields!amount1.Value, "dsmatrix1") + Sum(Fields!Tamount1.Value, "dsmatrix2")
Please help me to get a solution for this.
Thanks!
I think I know what's going on. Correct me if I'm wrong.
Based on what I'm seeing, I'm guessing that Matrix 1 and Matrix 2 only have three fields each, an ID field, an amount field (being "amount1" or "Tamount1"), and a year field.
Your column grouping is manipulating the display of the data to show all values broken out by year. This works fine when looking at data from a single dataset. However, your formula is specifying that the sum of everything in the Amount1 field of dsmatrix1 and the Tamount1 field of dsmatrix2 should be added. This does not take into account the column grouping. Your expression is essentially taking all of the values from both datasets and adding them together.
Not knowing more about your query structure or how the data is filtered, my best guess is that you need another SQL dataset. In this case, you would take the queries from your two previous datasets and union them with the "Union All" command. Note that you will want to use Union All and not just Union. More on that here: What is the difference between UNION and UNION ALL?
Your end result should look something like this:
--This will be your dsmatrix1 query copied and pasted
Select ...
Union All
--This will be your dsmatrix2 query copied and pasted
Select ...
--Place one single Order by clause at the bottom
Order by ...
Note: for your two queries to be unioned properly, you'll need to make sure that each have the same number of fields, each with the same data types. Then you can point your third matrix to the new dataset.
Hope that helps!