SSRS sum of distinct values - ssrs-2008

I want sum of only unique values in SSRS report.Is there any logic to achieve this.
this is what something like this sum(distinct value)
Thanks

Supposed you have a column named value in your query, you could do the following:
Add an additional column to the query of the dataset:
ROW_NUMBER() OVER (PARTITION BY [value] ORDER BY [value]) AS valueNr
Then, if you already have created a Sum field in the table, change the expression of the textbox to
=Sum(Iif(Fields!valueNr.Value=1, Fields!value.Value, 0))
Repeat this for every "distinct sum" calculation.

Yes. You use groups. At the top click the insert menu, then table, then Table Wizard. Pick your dataset and hit next. Now drag the column for the different types of items you want a distinct sum of into the Row Groups section. Drag your count column into the Values section. This should automatically turn it into Sum(ColumnName). You can click the down arrow to change the aggregate type (if desired). Press next and next and finish. Viola. You have a distinct sum for each specified field.

Related

How to sort combo box by frequently used?

So, simple question, I have combo box in my database and I want items that I have selected most frequently to appear first the next time that I add a record.
I would suggest adding a Long Integer field to the table consituting the row source for your combobox, and incrementing the value held by such field either on the AfterUpdate event of the combobox, or following the main operation being performed by your form.
Then, sort the items in the combobox by this new field in descending order.
I assume that your combo box selects a lookup value in for a property (PropertyID) that is saved in a table (MainTable).
You can get the number of times this property has been selected with
SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID
Now get the sorted lookup table by using this query as sub-query:
SELECT L.PropertyID, L.Name
FROM
LookupTable L
( SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID) X
ON L.PropertyID = X.PropertyID
ORDER BY X.SelectedTimes DESC, L.Name
I'm also sorting by name in case two entries have the same count.
As usage may change over time, you should record the time when an item was selected. Then you can weight the usage, so recent usage of an item have higher weight than those items used, say, a year ago.
Then you can run a query to list the usage having the most recently used items at top:
Select Item, Sum(1 / DateDiff("h", [SelectedTime], Now())) As Usage
From ItemUsage
Group By Item
Order By Sum(1 / DateDiff("h", [SelectedTime], Now())) Desc
Of course, this linear weighting may be too simple. You can apply any math to the usage like square or log.

How do I sort SSRS Table Column Group on an value in decending order?

How do I set this GroupExpression to order in descending order:  =Fields!ID_Count.Value in descending order?
To sort values in a group, including the details group, for a Tablix
1 On the design surface, click in the tablix data region to select it. The Grouping pane displays the row groups and column groups for the Tablix data region.
2 In the Row Groups pane, right-click the group name, and then click Edit Group.
3 In the Tablix Group dialog box, click Sort.
4 For each sort expression, follow these steps:
1 Click Add.
2 Type or select an expression by which to sort the data.
3 From the Order column drop-down list, choose the sort direction for each expression. A-Z sorts the expression in ascending order. Z-A sorts the expression in descending order.
5 Click OK.
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/sort-data-in-a-data-region-report-builder-and-ssrs

iReport multiple copies of same report with different label

I am using iReport 4.1.3. I have created invoice report and I want to have 3 copies of same invoice report. The first invoice should have label as "ORIGINAL", second should have "DUPLICATE" and the third should have label as "TRIPLICATE" on it.
Thank you.
If you would like to show all three copies every time you open the report, here is a creative if not elegant solution.
Add a cross join to the FROM clause of your query returning the three different copies. In MySQL it looks like this:
CROSS JOIN
(
Select 'ORIGINAL' as copy, 1 as sequence
UNION
SELECT 'DUPLICATE' as copy, 2 as sequence
UNION
SELECT 'TRIPLICATE' as copy, 3 as sequence
) x
Then add the "copy" field to your select statement. This will cause your query to return 3 records for each record it was previously returning. One record with "ORIGINAL" in the copy field, one with "DUPLICATE" and one with "TRIPLICATE". Add "sequence" to your ORDER BY clause.
Then in the report, group by the "copy" field. Force a new page for each group and you should be all set. Any variables you are totaling at the report level you will need to change to the group level ("copy" group). And if you have any controls in the Summary section, move them to the new group footer section. Also create a text field to display the "copy" field in the page or group header.
It's not necessarily pretty, but it should work.

Is it possible to create a row that spans all columns of a Matrix in SSRS 2008?

Is it possible to have add a row to an SSRS 2008 Matrix that spans all of the matrix's columns?
This crude diagram shows roughly what I'm looking for:
The basic idea is that each line item is a person, and each column is a field in a form for that person. The fields themselves are dynamic (and implemented as column groups on the matrix). Additional column groups are included to append non-dynamic form fields, like the time the record was entered and who entered it. Under each person's record is a comments field, which should span all of the form fields above it.
At the moment I have the matrix embedded in another tablix, with the name and fields in the matrix and the comments in the parent tablix. This works for the data (each instance of the matrix ends up being one row), but the header repeats too often (once per person) because it's attached to the matrix. The only thought I have as to how to fix this is to create another matrix in the parent tablix with the same grouping and use it to display the headers... But this will require quite a lot of manual synchronization to keep the two matrices the same.
Edit: The key problem here is making the second row span multiple column groups.
Here's what you can do:
Select the column grouping you want to add above and right click and select
Add Group... Parent Group...
Group the column by something that will not aggregate the data. You'll have to select a field from your dataset to group by so that it creates an overlapping column grouping.
Check the Add group header box
You should now see something similar to this:
Now you just need to move the Value1 field and it's header over under the new column to the right beyond the matrix dividers. Once that's done, simply delete the ungrouped column where you just copied Value1 from and be sure to select Delete columns only checkbox.
Your finished product should look like this:
It is possible - And the above answers are partial answers leaving out one key step: Merging the cells of the child row.
First, right click on your grouped row, then select Insert Row -> Inside Group - Below and you will get two rows with the cells aligning on the columns
Second, ctrl click all the cells in your new row (ie row without the data) then right click on one of the highlighted cells, and then select Merge Cells.
Now you have the table you like. To add a value to the new row: first right click your new (multi column) cell,select Create Placeholder, and then add the dataset item you desire to the placeholder.
[Edit]
After several attempts, I'm going to say this isn't possible in SSRS. The best I could come up with is a group footer that spans columns 1,2, and 3, but not the User column.
[Original Response]
I recently did something similar to this.
First, what tool are you using to create SSRS reports? (I used SQL Server Business Intelligence Development Studio)
You'll want to create a row group (grouped on Person)
Append a row to your table in "Design" view (Right click, "Insert Row --> Inside Group - Below").
Add an expression to the row that pulls the value for your "Comment" column (=Fields!Comment.Value).
Let me know if that helps...
Try adding in you column group "header" with a grouping expression of (1=1). Then a detail field will need to be defined. If you define the other group with correct data then the "header" will stretch across all details columns. You may need to merger depending on other options.
The easiest way to do this is to create a Tablix with only one column, and your row grouping.
Then, you create two rows inside this group.
In the first row inside the group, you insert a Matrix, wich you can then subgroup as you prefer.
I just had a similar problem, and this was my solution.
I banged my head against the wall for a lot of time, until i realized the solution to my problem wasn't "making a cell span multiple column groups", but "making a cell split into multiple column groups".
You can accomplish the goal by using a subreport for each person. The subreport will receive the employee id and create the hierarchy for you. Make sure your subreport column widths match the widths of the parent report.

How to show empty groups in crystal?

I have a report that shows items by goups.
Lets say he groups are:
In Inventory
In Process
When there is no data In Inventory, that row is not shown. any idea how to show a row with 0 inventory?
It sounds as though you are grouping on a field (such as stock item status), where there may be 0 rows returned for certain values of the field (such as In Inventory). The answer is to amend your query to right outer join to a lookup table holding all values of the grouping field, for example as follows:
select lu.status_value stock_item_status,
si.stock_item_status item_status,
si.stock_item_id,
coalesce(si.quantity,0) quantity
from stock_item si
right join stock_item_status lu
on si.stock_item_status = lu.status_value
This will now include a row returned for stock_item_status values with no corresponding stock_items, with null values for all of the stock_item fields.
If you were including a subtotal of stock_item.quantity values for each status, changing this to coalesce(...,0) should ensure that this null value is displayed as 0.
If I'm understanding you correctly, you've got a field {table.inventory} that holds the number of items in inventory that has a null value when the inventory is zero? When you group on this field you're not seeing the rows with null values in this field?
Crystal should still display those rows, just in a group with a null group name. To fix this you can go into the Group Expert -> Select the group in question -> Options -> Options tab -> Select 'customize group name field' -> and then specify a formula as a new group name field where you simply check to see
if isnull({table.inventory}) then 0 else {table.inventory}
Similarly, you can just create a formula that does this and group on that instead.