I am taking Top 10 of Sales Volume grouped by Product categories in SSRS 2012.
I need the total of these top 10 but it shows the complete total. I cant do it on dataset level as I need the complete dataset for other parts in the report. I tried the solution as given in MSDNlink but that didn't help either. Thanks in advance.
This sort of approach does actually work very well.
You haven't given any idea of what your data/metadata is like, but the concepts can be explained with a simple example. Consider the following data:
We will make a simple report based on this, grouped by the grp column:
Sort the groups by total val, from highest to lowest:
To get the running rank and the running total, we use the RunningValue function.
To get the Group Rank, use:
=RunningValue(Fields!grp.Value, CountDistinct, Nothing)
To get the running total use:
=RunningValue(Fields!val.Value, Sum, Nothing)
Finally, we need to display a total for the Top N values; in this case I'm displaying the top 2.
For the second group detail row, use the following Row Visibility expression:
=IIf(RunningValue(Fields!grp.Value, CountDistinct, Nothing) = 2, false, true)
That is, only display this row when there have been two groups, i.e. top 2. You could change the value as required.
This shows us one total row as required:
You need to apply these concepts to your data. If you're still having issues, I suggest trying to replicate my results with the above data/code to make sure you understand all the concepts involved.
Edit after comment:
For situations where there are fewer than N groups but you still want to display the last total, you need to add an extra check to the Top N row Row Visibility expression, something like:
=IIf(RunningValue(Fields!grp.Value, CountDistinct, Nothing) = 10
or (RunningValue(Fields!grp.Value, CountDistinct, Nothing) = CountDistinct(Fields!grp.Value, "DataSet1") and CountDistinct(Fields!grp.Value, "DataSet1") < 10)
, false
, true)
So now the expression will show the for the 10th row, or if the total number of groups in the DataSet are less than 10, it will show for the last group row.
It's a bit more complicated but it has worked for me in the past; depending on your data and report setup you might need to play around with the Scope a bit to get it working in your environment.
If you just need a total for those top 10 and not a running total, you can filter your table by top N ProductCategory and sort your ProductCategory group by SalesVolume Z to A.
For example, I have a table of sales orders and subtotals. I'm showing the top 10 highest total
I sorted by SalesOrderID group descending by my value (TotalDue). Then I filtered my table so it shows only top 10 SalesOrderID.
If you have a lot of data, you may have to see how this performs since I think the table filter happens at runtime.
I think I found an easy way to do that. I had many "Sums" in my report and I couldn't understand the way you answered.
The way i found was to create a parent group of the Details group and add a total row outside the Details. Then I hided the Detais group and the total group just did the Sums and in the group properties just needed to filter the final Sum top N rows, and sort by Z to A the Sum.
All of this worked fine and was done in the Group Properties! In the tablix poperties only showed 3 or 4 rows...
Related
I know this is not the first time someone is asking a similar question, but me trying to execute what I found out in other answers is not working exactly as how I want it to be. I hope someone here could help me.
I got four columns, the first one is the Product Name, and the last one is its P/L%. I want to sort out top and bottom 5 P/L% value along with their corresponding Product Name. I am attaching the screenshot of a sample scenario in case if you couldn't understand what I explained.
I tried the (sort(filter)) method as found somewhere else, but it actually messed up with the second and third columns. I hope someone here can give me some simple ways.
My solution considers the case when multiple products has same value in P/L% and I use a Table object for displayed data.
Formulas to use
Top 5 Gainers values
=LARGE(ProductTable[P/L%]; ROWS($H$3:H3)), and copy down
Top 5 Gainer values
Top 5 Gainers products name
=INDEX(ProductTable[Product Name];AGGREGATE(14;6;(ROW(ProductTable[P/L%])-ROW(D$2)+1)/(ProductTable[P/L%]=H3);COUNTIF($H$3:H3;H3))), and copy down
Top 5 Gainers products name
Top 5 Loosers values
=SMALL(ProductTable[P/L%];ROWS($H$3:H3)), and copy down
Top 5 Loosers values
Top 5 Loosers products name
=INDEX(ProductTable[Product Name];AGGREGATE(14;6;(ROW(ProductTable[P/L%])-ROW(D$2)+1)/(ProductTable[P/L%]=K3);COUNTIF($K$3:K3;K3))), and copy down
Top 5 Loosers products name
Short Explanation
You must use LARGE and SMALL functions when you want to get the largest or the smallest value in a data array.
AGGREGATE function is a little bit complex to explain here so I recommend you this link to understand better. Basically, I use this formula to get the row of the gainer or looser product name into INDEX function.
ROWS($H$3:H3) returns 1, but when you copy down this formula, you get 2, 3, and so on. This is a nice way to expand the query if you need more than top 5 values.
Similar problem in:
https://www.excelforum.com/excel-formulas-and-functions/1208726-index-match-large-and-duplicates.html
I have a dataset with 5 main categories and 26 subcodes. Each item falls under any one or more of the 5 categories and is assigned ~1-6 of the subcodes.
I'm taking the few thousand entries and breaking it down as shown below in the pictures.
Right now I am using filters to only show the items that have an "x" in the right columns and taking that data to a different tab where I use the =SUM(LEN(range)-LEN(SUBSTITUTE(range,"text","")))/LEN("text") to pull out a count of each subcode from column G. I'm mainly wondering if there's a quicker way to get around having to manually do the filter for each category combination.
Anybody got any ideas?
Thanks,
I'm trying to rank some data in spotfire, and I'm having a bit of trouble writing a formula to calculate it. Here's a breakdown of what I am working with.
Group: the test group
SNP: what SNP I am looking at
Count: how many counts I get for the specific SNP
What I'd like to do is rank the average # of counts that are present for each SNP, within the group. Thus, I could then see, within a group, which SNP ranks #1, #2, etc.
Thanks!
TL;DR Disclaimer: You can do this, though if you are changing your cross table frequently, it may become a giant hassle. Make sure to double-check that logic is what you'd expect after any modification. Proceed with caution.
The basis of the Custom Expression you seem to be looking for is as follows:
Max(DenseRank(Count() OVER (Intersect([Group],[SNP])),"desc",[Group]))
This gives the total count of rows instead of the average; I was uncertain if "Count" was supposed to be a column or not. If you really do want to turn it into an average, make sure to adjust accordingly.
If all you have is the Group and the SNP nested on the left, you're done and good to go.
First issue, when you want to filter it down, it gives you the dense rank of only those in the filtered set. In some cases this is good, and what you're looking for; in others, it isn't. If you want it to hold fast to its value, regardless of filtering, you can use the same logic, but throw it in a Calculated column, instead of in the custom expression. Then, in your CrossTable Aggregation, get the max of the Calculated Column value.
Calculated Column:
DenseRank(Count() OVER (Intersect([Group],[SNP])),"desc",[Group])
Second Issue: You want to pivot by something other than Group and SNP. Perhaps, for example, by date? If you throw the Date across the top, it's going to show the same numbers for every month -- the overall numbers. This is not particularly helpful.
To a certain extent, Spotfire's Custom Expressions can handle this modification. If you switch between using a single column, you could use the following:
Max(DenseRank(Count() OVER (Intersect([${Axis.Columns.ShortDisplayName}],[Group],[SNP])),"desc",[Group],[${Axis.Columns.ShortDisplayName}]))
That would automatically pull in the column from the top, and show you the ranking for each individual process date.
However, if you start nesting, using hierarchies, renaming your columns, or having multiple aggregations and throwing (Column Names) across the top, you're going to start having to pay a great deal to your custom expression. You'll need to do some form of string replacement around the Axis.Column, or use expression instead of Short Names, and get rid of Nests, etc.
Any layer of complexity will require this sort of analysis, so if your end-users have access to modify the pivot table... honestly, I probably wouldn't give them this column.
Third Issue: I don't know if this is an issue, exactly, but you said "Average Counts" -- Average per day? Per Month? When averaging, you will need to decide if, for example, a month is the total number of days in month or the number of days that particular payor had data. However you decide to aggregate it, make sure you're doing it on the right level.
For the record, I liked the premise of this question; it's something I'd thought would be useful before, but never took the time to try to implement, since sorting a column or limiting a table to only show the top 10 values is much simpler
I'm trying to design a second page that shows % results of my data on page 1.
For example, Column F & G allow manual entry of numbers 1-4 which are based off data the user types in at another location.
This is being used for trade tracking in investments so there will be quite a few numbers but the end result will be a row will show a specific stock, it's subsequent data, whether it made or lost money, etc.
What I want to do in page 2 is using the numbers 1-4 which were typed in at columns F & G, translate that into an edge on page 2.
For example, if there were 50 columns of data typed out for trades executed, I could take the number of winning trades of a certain setup (say number 3) and divide that by the total trades of 50 to come out with a win % for that setup.
However, I have no clue to how to translate that forumla into a filter formula so that on page 2 I could see that of the numbers 1-4 (4 different setups) I could easily see the highest and lowest win % to determine the best setup to use.
I'm not the best in excel but I understand enough to code most of that, I simply have no idea how to take that end formula and add a filter to it so that it only uses partial results. I've got 4 other formulas I want to use on page 2 as well to help build something that could really benefit myself, but if someone could just show me how to filter data into a formula, I think I could take it form there.
Thanks for the help
Ben
You can also do something like this with array formulas
=MAX(IF(Sheet1!$F$2:$F$50=$A2,$E$2:$E$50))
(Press Ctrl+Shift+Enter [CSE], instead of just Enter when entering Array Formulas)
Also, take a look a the SUMPRODUCT function. It comes in very handy for filtering data. Here are some helpful links...
https://www.get-digital-help.com/2017/12/07/sumproduct-multiple-criteria/
https://www.get-digital-help.com/2017/12/08/sumproduct-and-if-function/
https://www.get-digital-help.com/2010/09/01/extract-a-unique-distinct-list-by-matching-items-that-meet-a-criterion-in-excel/
I'm not a developer but I'm supposed to create a report by C.R., so excuse me in advance if it is an obvious question for you, and please keep in mind that I'm a real beginner.
I have a job composed of 3 different workings (3 out of 5, which is the maximum workings I can have for a job).
In my SQL database, the table.field corresponding to those workings is job.phase, so when I put, in my report details, the field "job.phase", I get 3 rows for that job.
The point is that my report printout always has to show 5 different text objects (one below the other), corresponding to the descriptions of all the 5 possible table.field-records, and a 'X' should appear next to text objects when each one of the workings listed there is a part of my job (otherwise nothing should appear).
What I have done is the following:
- created a subreport containing the "job.phase" field
- put it near my first text object
- specified in my subreport the following "show string" formula:
if job.phase = 'working1' then 'X' else ''
and it works: a X appears if working1 is part of my job, nothing appears if working1 is not part of my job.
Then I have created 4 subreports more, equal to the first one, and specified the same for job.phase = working2, working3, working4 and working5, BUT, after doing that, no X is shown (even though working 1, 2 and 3 are part of my job)...
Is there anybody who can help me, please? It's so frustrating...
Using subreports for something like this is overkill for what you're trying to do and could be causing any number of things to behave badly. I'd recommend you abandon that idea. Here's how I would do it:
The first thing you'll want to do is group by job (if more than one will appear in your report, which I'll assume it will). The Group Footer section is where you can display the labels and Xs. You'll need to create 5 formulas as you did before if {job.phase} = "working1" then "X", one for each of the phases/workings. Drop all 5 of those formulas into the Details section of the report and then suppress that entire section so that it doesn't display.
To show the Xs, you can use a Maximum summary in the Group Footer for each of the five formulas you created. To do this, right-click each of the formulas in turn, select Insert -> Summary. Choose Maximum as the summary, and "Group 1" (Your job ID or whatever field you are using to group the job) as the Location. That will insert a field into the Group Footer that will display an X when that particular working is specified for the job, otherwise it won't display anything. Move them to display next to the appropriate label/text field and you're done.