Tableau Grouped Stacked Bar Charts - bar-chart

I'm working with some multi-year, multi-category data, multi department data. So I've created stacked bar charts for each year where the bars are the department and the stack is the category. Like so:
However I cannot for the life of me figure out how to put each department next to each other and show multiple years side by side. Can anyone point me in the right direction?
My data looks something like this:
Category, Dept, 12_13, 13_14;
1 , A , 10 , 20 ;
2 , A , 22 , 1 ;
1 , B , 5 , 32 ;
2 , B , 34 , 7 ;

Right click on your department Dimension and set the defaul sort as desired. I think that might solve what you're trying to do.
http://onlinehelp.tableau.com/current/pro/online/en-us/help.htm#datafields_fieldproperties_sort.html

Related

Aggregate values and display in chart

I am struggling with this problem and I can't figure out how to solve it.
This is my dataset detail data:
Order Item StartDay EndDay EndYear StartEndDiff
1 1 01.01.2018 02.01.2018 2018 1
1 2 03.01.2018 05.01.2018 2018 2
2 1 05.01.2019 06.01.2019 2019 1
2 2 06.01.2019 06.01.2019 2019 0
2 3 08.01.2019 10.01.2019 2019 1
3 1 07.01.2019 08.01.2019 2019 1
I now group them by Order (this works fine in a tablix). Group name is OrderGroup:
Order MinStartDay MaxEndDay EndYear MinStartMaxEndDiff
1 01.01.2018 05.01.2018 2018 4
2 05.01.2019 10.01.2019 2019 5
3 07.01.2019 08.01.2019 2019 1
For MinStartMaxEndDiff I got the following expression:
=DateDiff("d", Min(Fields!StartDay.Value, "OrderGroup"), Max(Fields!EndDay.Value, "OrderGroup"))
Now I added another group in the tablix and displayed the Avg(MinStartMaxEndDiff) per EndYear. This still works fine in the tablix with all the groupings. The result:
Avg(MinStartMaxEnd) Year
4 2018
3 2019
But I can't figure out how to display only the data from the result, based on the calculations, in a chart. I normally do these calculations on the SQL side, but this time I can't do them SQL side.
The problem is when I try to add the OrderGroup in the chart it always shows me the details. But I need this group to get the right values. Hide or set the category label to Nothing didn't work. Also setting the DataElementOutputto NoOutput didn't help (real look):
I would just need on the x-axis the Years and as values the Avg(MinStartMaxEnd). This would be my desired output based on the sample data from above:
EDIT AFTER A SOLUTION WAS FOUND:
What can I do if a row data looks like this:
Order Item StartDay EndDay EndYear StartEndDiff
1 1 29.12.2018 02.01.2019 2019 4
1 2 28.12.2018 30.12.2018 2018 2
This one will get divided into two separate datarows in the tablix, because of the EndYear grouping. The expected result should be look like this:
Order MinStartDay MaxEndDay EndYear MinStartMaxEndDiff
1 28.12.2018 02.01.2019 2019 5
But a grouping of the year with the expression
=Max(CDate(Fields!EndYear.Value), "OrderGroup")
is not possible.
You can use custom code inside your tablix to calculate the average per year, and call the calculated values in the chart.
Add the following custom code to your report
Public Dim YearAvg As New System.Collections.Generic.Dictionary(Of String , Decimal )
Public Function SetYearAverage( ByVal s As String, ByVal d AS Decimal) As Decimal
YearAvg.Add(s,d)
Return d
End Function
In the textbox you calculate the year average change the expression to the following (make the appropriate changes to field names)
= Code.SetYearAverage(Cstr(Fields!EndYear.Value), Avg ( DateDiff("d", Min(Fields!StartDay.Value,"OrderId"), Max(Fields!EndDay.Value,"OrderId"))))
Then set your chart expression to
= Code.YearAvg( Cstr( Fields!EndYear.Value))
This is not an answer as I didn't get the results you were expecting, work got in the way! However, it's fairly close so I thought I would post it in case it was any help.
A pity doing this on the server was not an option as it would be really easy.
Anyway, I replicated your dataset (with a couple of field name changes to avoid keyword conflicts) and set the chart up as follows..
Category groups - None
Series Groups 2. Parent group is on 'EndYear' called 'ChartYearGroup', child group is on OrderID called 'ChartOrderGroup'
Values - Here I set the Category Field to [EndYear] and the expression was
=AVG(DateDiff(
"d"
, Min(Fields!StartDay.Value, "ChartOrderGroup")
, Max(Fields!EndDay.Value, "ChartOrderGroup")
)
, "ChartYearGroup"
)
This does give the correct numbers but unfortunately shows per order rather than per year.
I'm not sure if this will be possible to resolve. Somehow I guess you'll have to hide the order group or combine the two groups into one, I just ran out of time to test.
Here's the end result.

How can I make empty groups of a bar chart visible in SSRS?

I have a bar chart that displays # of Work Orders on the X axis and groups them into 3 categories on the Y axis (Overdue, 0 to 7 days, 8 to 28 days). The report is setup for the user to select a parameter (in this case an NYC boro) in order to run the report. In some cases, the borough selected does not return values for all 3 of the groups on the Y axis. How do I force SSRS to display all of the categories on the Y axis even when those groups are empty. In the example image included, the "0 to 7 Days" category is not showing up.
You need to create a table with a list of your categories in and then left join your current query to that. Without seeing your current query I can;t give the best answer as you may already have all the categories in a table that you could already use but this will still work...
DECLARE #cat TABLE(CategoryName varchar(20))
INSERT INTO #cat VALUES
('Overdue'),
('8 to 28 days'),
('0 to 7 days')
SELECT
c.CategoryName, q.*
FROM #cat c
LEFT JOIN (SELECT * FROM YourOriginalQuery) q
ON c.CategoryName = q.myOriginalCategoryName
As you are now left joining from a list of categories, each category name will be present in your dataset (unless of course your WHERE clause filters it out).
If you edit your question showing your current query, there may be a much better way to achieve the same result.

Graphing a single row in an SSRS Line Graph

I have a table setup with the following columns:
Product Name
SalesMonth1
SalesMonth2
SalesMonth3
SalesMonth4
SalesMonth5
An example of a row is as follows:
Bread
300
600
800
900
1000
I am trying to put this into a line graph in SSRS but am having trouble figuring out which fields go where. In my dataset, I have a field for each "SalesMonth" column. So in my dataset, I have 6 fields total including the product name. Will this work? On which axis should the product name go and the sales fields go?
I hope your dataset uses SQL.
I would "unpivot" the data by writing a 5-part UNION SELECT, e.g.
SELECT Product_Name , 1 AS Month , SalesMonth1 AS Sales
UNION ALL
SELECT Product_Name , 2 AS Month , SalesMonth2 AS Sales
UNION ALL
...
SELECT Product_Name , 5 AS Month , SalesMonth5 AS Sales
Then in the SSRS Chart definition:
Month = Category Group
Product Name = Series Group
Sales = Values
But the real real answer is that your data is probably not in a useful shape for reporting. Will there only ever be 5 months? I suspect not...

How to add SSRS page break after 65536 rows, counting group header/footer

I have an SSRS report which is failing to export to excel when the row count is greater than the Excel 2003 limit of 65536
The report already has a grouping level with a group footer.
I have tried to add an extra grouping level with a page break on the expression
=ceiling(rownumber(nothing)/65536)
However, this counts the detail rows, but does not take into account the group footer. So the rownumber evaluates to 53000 while the actual number of rows has exceeded 65536.
The following expression
=ceiling(RunningValue(Fields!myfirstgroup.Value, CountDistinct, Nothing) + rownumber(nothing) / 65536 )
will give me the actual row count including the group footers, but SSRS will not allow a group on a running value expression.
How can I force a page break after 65536 rows to allow an export to Excel? I had hoped to accomplish this in the report definition, and avoid adding a calculated page number in the query .
Any help much appreciated
* UPDATE - Sample data *
ItemDescription , Location , Quantity
Red lorry , M25 , 5
Red lorry , M6 , 2
Yellow lorry , M1 , 3
Report has a grouping on ItemDescription with a total for that item, so it will show
ItemDescription , Location , Quantity
Red lorry , M25 , 5
Red lorry , M6 , 2
Total for Red Lorry,7
Yellow lorry , M1 , 3
Total for Yellow Lorry,3
This means from my 3 rows of data, I have 5 report rows including detail and footer rows. SSRS can tell how many details rows are in my dataset, but I need to take the footers into account for a page break.
Hi this link might help you. I had similar sort of issue, a few years back.
SSRS Page break on Tablix with Rownumber ,just one row group and no group expression given by default
=Floor((RowNumber(Nothing)-1)/2000)
was the suggested answer
Create a group with the following expression:
=CInt(Ceiling(RowNumber(nothing)/65000))
The 65000 give you a little extra room for any headers or footers. Next, do a Page Break on this group "Between each instance of a group" and "Also at the end of a group" and you will successfully beat the excel file limit issue.
This is what we normally use without any issue. I don't think any one will notice if you don't specifically use all 65,536 rows.

How would I do this in MySQL?

Lets say I have a database of widgets. I am showing a list of the top ten groupings of each widget, separated by category.
So lets say I want to show a list of all widgets in category A, but I want to sort them based on the total number of widgets in that category and only show the top 10 groupings.
So, my list might look something like this.
Top groupings in Category A
100 Widgets made by company 1 in 1990.
90 Widgets made by company 1 in 1993.
70 Widgets made by company 3 in 1993.
etc...(for 10 groupings)
This part is easy, but now lets say I want a certain grouping to ALWAYS show up in the listings even if it doesnt actually make the top ten.
Lets say I ALWAYS want to show the number of Widgets made by company 1 in 2009, but I want this grouping to be shown somewhere in my list randomly (not first or last)
So the end list should look something like
Top groupings in Category A
100 Widgets made by company 1 in 1990.
90 Widgets made by company 1 in 1993.
30 Widgets made by company 1 in 2009.
70 Widgets made by company 3 in 1993.
How would i accomplish this in MySQL?
thanks
Edit:
Currently, my query looks like this
SELECT
year,
manufacturer,
MAX(price) AS price,
image_url,
COUNT(id) AS total
FROM
widgets
WHERE
category_id = A
AND
year <> ''
AND
manufacturer <> ''
GROUP BY
category_id,
manufacturer,
year
ORDER BY
total DESC,
price ASC
LIMIT
10
);
Thats without the mandatory grouping in there.
The placement doesnt necessarily have to be random, just shouldnt be on any extreme end. And the list should be 10 groupings including the mandatory listing. So 9 + 1
I would use an UNION query: your current query union the query for 2009, then handle the sorting in the presentation layer.
You can write 2 separate query (one for all companies and another just for company 1) and then use UNION to join them together. Finally, add ORDER BY RAND().
It will look like
SELECT * FROM
(
SELECT company_id, company_name, year, count(*) as num_widgets
....
LIMIT 10
UNION DISTINCT
SELECT company_id, company_name, year, count(*) as num_widgets
...
WHERE company_id =1
...
LIMIT 10
)x
ORDER BY RAND();
You could add a field that you make true for company 1 in 2009 and include it in the where clause. Something like
select * from companies where group = 'some group' or included = true order by included, widgets_made limit 10
For the random part you would have that as subquery then include a column that has a random number from 1 to 10 if the field that you made is true, and rownum otherwise, then sort by that column