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

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.

Related

Get all unset values with spring hibernate jpa

Let's say there is a table like the following:
id | number
----|----------
1 | 1
4 | 6
5 | 2
14 | 3
now I need all numbers that are not set between 1 and the highest number that is set. Here the highest number is 6, so I need all numbers that are not set between 1 and 6. Here it is: 4 and 5
But how can I achieve this with spring and hibernate jpa with a MySQL database?
The highest number is easy. Sort numbers DESC and then the first one. But then return all missing numbers that are not in the database? Is this possible?
One way: select each number that is smaller then the highest number and check if the returned object is null. So first check 5, then 4, then 3, ... But this is of course very slow on big databases.
So another idea was: get all numbers that are set and get the missing numbers on java side with the difference of two lists (one list with the numbers out of the database, the other list with the numbers from 1 to the highest number of the database). But on big databases it is also dumb to get everything. (Let's say, there are 1 million entries and only one number is missing.)
The third idea: something like select where number NULL would be perfect. But for this the database would have to be initialized with all possible numbers ever there. So that is also not possible.
Is there a possible way? Am I overseeing something?

Count the number of times a record appears and place in a bucket, SSRS

More head banging for something that I'm sure is an easy solve. I'm attempting to count the number of accounts that appear in a dataset more than once, but less than 6 times. I can't even get the code to count the number of instances that accounts appear more than 2x's.
123
123
456
456
111
111
111
I should be able to say that the above dataset based on my query = 3. I want to count 123 as 1 instance, 456 as 1 instance and 111 as 1 instance since they all appear greater than or equal to 2 times. After I figure this out, I should be able to get to the point where I can do my buckets. But, I can't seem to breakthrough this part yet.
I have tried this, and it works, but doesn't give the result I want. It gives me the number of records in the data set.
=IIF(count(Fields!AcctID.Value) >= 2, Count(Fields!Instance.Value),0)
I have also tried this, and it also gives me the same result as the code above:
=Count(IIF(Fields!AcctID.Value >= 2, Fields!Instance.Value,0))

SSRS tablix split report into two sets of columns

I have a report that lists some basic data about a company for all (possibly) 52 weeks of the year. The report takes in parameters of year and UptoWeek. So for example i can put in 2013 and 31 and it will spit out all the values for year 2013 up to week 31. Right now it looks like:
Week Dollars PY Dollars Change
1 5 4 1
2 20 25 -5
...
52
I want it to split into two sets of columns at the halfway point, so the left side is 1-25 and the right side is 26-52 like so
Week Dollars PY Dollars Change Week Dollars PY Dollars Change
1 5 4 1 26
2 20 25 -5 27
... ...
25 52
Is this possible in tablix?
The one thing I was thinking was to just copy the tablix next to itself and hide rows higher than 25 on the left, and lower than 26 on the right. I'm just not sure if that's the best way to handle this...
You could set up a column group based on an expression like:
=IIf(Fields!Week.Value <= 26, 1, 0)
Note that this is set to 26, as 26 really should be on the left side, I think.
Your row group expression will need to be something like:
=(Fields!Week.Value - 1) Mod 26
So say I have data like this:
(snip)
And a tablix like this, grouped as above:
With the above grouping, this works for me:
(snip)
This will split your data into two groups based and week and as such will meet your requirements. Since you're only interested in two groups and have a ready-made row number in Week, you can keep the expression simple.
Side-by-side tablixes would most likely be fine, too, but SSRS is notoriously temperamental with adjacent objects. Using grouping as above keeps this as one item at the designer level.

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!

how to push data down a row in sql results

I would like help with sql query code to push the consequent data in a specific column down by a row.
For example in a random table like the following,
x column y column
6 6
9 4
89 30
34 15
the results should be "pushed" down a row, meaning
x column y column
6 null or 0 (preferably)
9 6
89 4
34 30
SQL tables have no inherent concept of ordering. Hence, the concept of "next row" does not make sense.
Your example has no column that specifies the order for the rows. There is no definition of next. So, what you want to do cannot be done.
I am not aware of a simple way to do this with the way you are showing the table being formatted. If your perhaps added two consecutively numbered integer fields that provide row number and row number + 1 values, you could join the table to itself and get that information.
After taking a backup of you table:
Make a PHP function that will:
- Load all values of Y into an array
- Set Y = 0 (MYSQL UPDATE)
- load the values back from PHP array to MYSQL