SSRS - Display only Top N Category Groups excluding duplicate groups at the end in Bar Chart - sql-server

Consider the following table
I need to generate a bar chart with the Category Group = "Country". The chart should only display the top 3 Groups based on the count of records for a country. I have already applied a filter for the Category Group specifying the Top N Condition as 3 for Count(Country). The chart generated, applies the filter as expected based on count, but i need only 3 bars to be shown even if there are bars with duplicate values.
Below is the chart that I get.
Expected Result
Now I know that, i can create an additional column in my dataset with ranking values and then apply a filter on this column to get the expected result (i have tried this, and it works)
Is there a way to achieve the expected result without changing the underlying Dataset?
Note: The dataset shown above is a highly simplified version of my dataset. In reality i have a huge dataset with a lot of columns. The same dataset has been used for various charts (with groupings on different columns).

This was an interesting question as I've always just "solved" the tiebreaker in the dataset without much thought. However, I do see a fairly easy way to use the rnd() function to dissolve the ties as long as you don't care which of the tied countries is shown:
=(Count(Fields!Country.Value) * 1000) + (Rnd() * 100)
Which essentially just weights the count per country into the thousands and then tiebreaks with a random small value:
New York: 30XX
France: 20XX
China: 10XX
Italy: 10XX
Singapore: 10XX
If you wanted to actually solve the tiebreaker with an alphabetical preference, you could do something similar but incorporate the numeric value for the first letter of the country etc...

I just found out, I could use an x-axis minimum of 0 and an maximum of 10.5 together with an interval setting of 1.
So, I was able to achieve a top 10 limitation and the axis labels show the names - (it may be a side effect but when I changed the axis maximum to a whole number, the axis no longer shows the names but numbers).
I was not really happy with the other approaches. They seems much of an overkill to me for such a simple requirement like limiting the number of bars shown in a chart.

Related

Excel: Need to Generate IDs based on multiple criteria with repeating IDs

Looking to create pricing groups bases on multiple criteria. Each group could have multiple items within the group. I'm struggling with the autocreation the naming of each group. I estimate there should be about 6.5K pricing groups out of 14K items.
Below is the criteria -
QTY per case - is the number of bottles in a case
Size - size of the bottle
Family Brand - contains a group of like items
Code - CS1 - This is my unique code for each group that contains each of the above and lowest possible case price.
enter image description here
The "Thinking" column is how I want each group to look, but how do I do this with 14K items quickly?
If I understood correctly your pricing group name consists of two parts: a simple combination of columns and a "special" column, that should be counted.
Part 1 is simple: =C2&"-"&B2&"-"&A1&"-"
To make Part 2 easier you could sort, sorting fields Part 1, CODE-CS1.
After have done this you could use helping columns. If Part 1 is in column x and code-CS1 in column y you could find a formula for
Part 2 (column z): ="T"&IF(X1=X2;IF(Y1=Y2;Z1;Z1+1);1)
That means: If Part 1 is changing your counter starts with T1, if not so if your CODE CS1 changes, it counts, if not, so it keeps last number.
the result code would be =X2&Z2
It is untested and I use german excel, maybe the code doesn't work without any adaption, but in general it should work

How to multiply values within a nested array...times values in an another array (in Google Sheets)?

This is hard to explain so my title sucks, and is just my best guess at how I might be able to approach this. I have a Google Sheet of sales data for cases of various bottle sizes of kombucha. Column E is the sale date, Column G contains the item code, and column J is the quantity sold of said cases. See my (vastly simplified) sample data:
https://docs.google.com/spreadsheets/d/17-LzGrNJtBr-FwOZtdaoCws3ayeGOHu_TdtGOfXj4cA/edit?usp=sharing
See my current test code below (also present in the Formula tab of the linked spreadsheet). It successfully gives me the combined number of cases sold of half-liter bottles and Growlers. The values in E4 and E5 are cells containing my start and end dates, respectively, so I'm constraining the results only to those which fall within a certain date range.
This code works, but now I need to figure out a way to sum the total number of bottles sold instead of # of cases. The data set is already massive and pushing the limits of google sheets, so adding a column to the source data sheet with # of bottles per case is not an option. Half liter cases hold 13 bottles, and growlers hold 5. Is there any way to do this with my current approach, using another array perhaps? Or any other approach that keeps the formula as simple as possible?
FYI the current formula is a proof of concept and I will be adding many additional types of cases to the existing formula, each containing a different number of bottles per case, and using it as part of a larger dynamic formula that allows you to switch between showing # cases vs # bottles vs # of actual liters sold, so this is why I am hoping to find an array-based approach that will let me do this without needing to resort to an absurdly long and complex formula of nested IF statements.
=SUMPRODUCT(--((XeroInvoiceData!$E$3:$E>=B4)*(XeroInvoiceData!$E$3:$E<=B5)), (--(ISNUMBER(MATCH(XeroInvoiceData!$G$3:$G, {"HalfLiterCase","GrowlerCase"}, 0)))), XeroInvoiceData!$J$3:$J)
I would be eternally grateful for any assistance.
Here is my solution:
https://docs.google.com/spreadsheets/d/1ig0krumJu4Lj9-nIKJyRfPLTYbU-mzOL0JokRUDEqNc/edit?usp=sharing
My idea was to filter your table on date and sum by the type of container.
I wanted also to allow new types of containers that contain smaller units (bottles or liters).
I divided this job into 3 stages.
First we have to filter this table according to selected dates and container types.
I prepared a list that may be extended (all you need is to extend the filter range).
Then I have to vlookup values of units in each container and I try to do it inside the same formula.
General idea is
={[query results],arrayformula(ifna(vlookup([first column of query],$C$21:$D$26,2,0)*[second column of query])}
I divide it into 2 stages.
First stage referrs to query results in adjacent table:
Second stage uses indexes of query so formula is quite long:
Tell me if it solves your problem.

Using multiple dataset in the same chart with different values

I am using react-chartjs-2. I have a Line chart and x: time y: value. I have 2 different dataset. First dataset value is very as low as 0.00000145 and etc. The second dataset value is as high as millions. When i use this in the same chart, first dataset is at the bottom and looks like a single straight line as chart comparing 2 datasets. Time is same for both datasets. So what is the best way to see two different datasets self comparing?
I think, the best way is to make single chart, which will show correlation between two datasets - the division of first dataset's values by another's. I think, it may be representative

Return only single max value row in Power BI Desktop

I have the following table of Parts which are sold for a particular job, which is the Order Number.
I am trying to extract just the Description of the most expensive part so that I can put it onto a single value card.
I have tried for a day mucking around with CALCULATE, MAX, TOP, SELECTEDVALUE, I cant seem to figure it out. I'm sure it is something simple too...
Would appreciate it if somebody can help me retrieve it in a way that I can see what I missed and learn for future.
My page is filtered by DrillThrough on the Order Number which filters the parts list for me.
Essentially, I just want the card to show 'PUMP,DTH,ELE'. My approach was to just select the top 1 row when the parts list is sorted descending by Amount in LC but it so far has not been as simple as that :(
Should it be a calculated column or measure on my Order table which has that string?
You should be able to create a measure that does this and then place that measure on a card.
Most Expensive Part = LOOKUPVALUE(Parts[Description],Parts[Amount],MAX(Parts[Amount]))
The MAX(Parts[Amount] piece gives you the maximal amount. Then you look up the description corresponding to that amount.

Wrap a SQL Reporting Matrix

I have a matrix in SQL reporting and I would like it to print on an A4 page. If the matrix has less than 4 columns then it fits but for more than 4 columns I would like the matrix to wrap and show only 4 columns per page. Is this possible? I am using SQL Reporting 2005 in localmode.
I found a work around:
First I added a field to my datasource called column count. Because the datasource is built in a business object it was easy for me to tell how many columns of data there is.
Next I created a list on my report and moved my matrix into the list.
I made the group expression =Ceiling(Fields!ColumnCount.Value/4) for the list.
In short I am telling the list to break every 4 columns. This causes the matrix to be split after 4 columns.
This will not work in all scenarios and probably screws up subtotalling but it worked for my application.
Disclaimer: this was not my idea...I adapted it from Chris Hays's Sleezy Hacks.
There is no way to intrinsically wrap columns; Mboy's solution above is very similar to what I have done in the past so I won't repeat his steps here, although I will warn you: for matrices with a large number of columns you will grow the number of pages in your report exponentially. In your case this may not be a problem; but we have found that in most cases it is cheaper ( in terms of page output) not to wrap columns.
Further to MBoy's answer, I wanted to show multiple charts on one page, but the number of charts would vary depending on the data. What I wanted was to show two charts on a row with as many rows as necessary. I did as follows:
As suggested by MBoy, I created a 'Count' field called [ChartNumber] in the data that increases by one for each chart (so if I had 7 charts, rows would be numbered 1-7).
To achieve this I used the DENSE_RANK() SQL function to create a field in my query, such as DENSE_RANK() OVER (ORDER BY [Data].[ItemtoCount]) AS [ChartNumber].
So if I wanted a different chart for each department I might use DENSE_RANK() OVER (ORDER BY [Data].[Department]) AS [ChartNumber]
I added a list to the form and bound to my dataset
I then set the row group to group on =Ceiling(Fields!ChartNumber.Value/2)
I then added a colum group on =Ceiling(Fields!ChartNumber.Value Mod 2)
Create a chart inside the list and preview, and you should see two charts side-by-side on each row.
I used charts, but you could easily put a matrix or any other item inside the list.
Edit: A more general solution for n columns is =Ceiling(Fields!ChartNumber.Value / n) and =Ceiling(n * Fields!ChartNumber.Value Mod n)
I don't think so. I've found that exporting to excel then printing was the most flexable way of printing SSRS matrix reports I've found - esp. since most of my users know excel well.
According to MSDN, Tablix data regions do pagination horizontally in much the same way a table does it vertically, which is to say you can specify a page break on a group change. There is another MSDN article that suggests the use of a pagination expression, but this technique is already explained by MBoy so I won't repeat it, except to say that it is an endorsed technique.

Resources