How to let the user select Bar Graph - Series parameter dynamically on Superset - bar-chart

I've a dataset with multiple classifications for the items as below
item | class_1 | class_2 | class_3
-----------------------------------------
item_1 | type_1a | type_2a | type_3a
item_2 | type_1b | type_2b | type_3b
item_3 | type_1a | type_2b | type_3c
On Superset I'm creating a BarGraph which shows the count as below
X-axis - Classification type and Y-axis - Count of Items
Since there are multiple classifications available, I should be able to select the type and correspondingly the chart should show the bar graph for that type of classification on X-axis
I've considered going for stacked distribution but that gives a clumsy experience.
Is there any way that I can let User select the X-Axis Parameter and then show the corresponding chart?

In the chart editor your end-user should be able to select the X-axis from a list of columns (class_1, class_2,...). You can edit your datasource to only display "groupable" columns (columns allowed in the X-axis) if you so choose.
You could always save two versions of the chart (one for each X-axis variable) to a dashboard.

Related

SSRS Report - Horizontally Sort Columns Across Column Groups

I am creating an unusual SSRS report that requires that the user be able to use parameters to select which of the (more than 250) fields appear in the report. So the number of columns in this report can vary greatly.
I've been mostly successful at implementing this, but am stuck at controlling how to change the order of the columns.
Here is (a simplified example) of my original data:
My data as a screen capture
CompanyID | Address | Website_URL | Date_Created | Date Modified |
1 |123 Main Street|www.fake.com | 3/14/2019 | 3/15/2019 |
2 |555 Park Ave |www.notreal.com|3/12/2019 | 3/13/2019 |
The first thing I've done is to unpivot my data within my dataset (i used cross apply to do this). The name of what the column used to be is kept in a column named something like "Col_1", and the value is kept in a column named something like "Val_1". The trick is, I have to do this multiple times, once for each data type that I'm dealing with. Because obviously you can't have dates and nvarchars in the same column. When I unpivot the data above, it looks like this:
CompanyID | Col_1 | Val_1 | Col_2 | Val_2 |
1 |Address |123 Main Street | Date_Created | 3/14/2019 |
1 |Website_URL |www.fake.com |Date Modified | 3/15/2019 |
2 |Address |555 Park Ave |Date_Created |3/12/2019 |
2 |Website_URL |www.notreal.com |Date Modified |3/13/2019 |
The point in doing this is now I can create a matrix is the SSRS report with the CompanyID as a row group. Then I create two adjacent column groups for Col_1, and Col_2, which have as their values Val_1 and Val_2, respectively.
Click here to see SSRS Groupings
Now, when this report runs, each column group (for example, Col_1) expands out to show all the column names I had under that column in my unpivoted data. This could be dozens of columns. This picture shows what my final data looks like. This is similar to what my original data looked like. But with the benefit of the fact that the columns are being displayed dynamically.
My resulting Matrix
So, the only problem I'm having is that the columns are stuck within their groups. Say I want to sort them alphabetically, I can only sort the nvarchars together, and the dates together. I cannot sort the across their groups. Is there a way I can do this?
The resulting Matrix I want, with columns sorted alphabetically
Thanks in advance for any ideas.
Using your original unpivoted data, the design of your report needs to have 4 column groups.
1.Address
2.Date created
3.Date modified
4.Website URL

DB structure - form with dynamic number of options

I've been reading similar questions, but I think my case is a bit more complicated.
I have a form that register items. These items may have options with sub-options (checkboxes and radio buttons):
The number of checkboxes and radio buttons may decrease/increase but the real pain to design a good structure is for the checkboxes, as these must have (at least I think so) a fixed name column for each one.
The case for radio buttons is easier as I just assign an id to each one (and save the names in a different table).
My current DB structure is simple (between parenthesis is the table/column name):
The items table (item) have columns of type integer (to save the id of the radio buttons).
Another table for the checkboxes (item_option), with columns of type integer (1 if checked, 0 if unchecked). And 1 PK column (item_id) that points to the PK column (id) of the items table.
And tables (again item_option) for the names of the radio buttons with a PK column (id) that points to the option column (is this understandable? Sorry for my bad english).
I think a different table containing the sub-options is better than put all the columns in the main table, right?
So, the radio buttons are stored in the main table (1 column per option) and the checkboxes in a separeted table (1 table per option):
Items table:
+-----+----------+----------+
| id | Option_1 | Option_2 |
+-----+----------+----------+
| 123 | 3 | 1 |
+-----+----------+----------+
| 456 | 2 | 3 |
+-----+----------+----------+
| 789 | 1 | 2 |
+-----+----------+----------+
item_option_3 table (this would be needed to know which ones are checked):
+--------------+--------------+--------------+---------+
| Sub_Option_1 | Sub_Option_2 | Sub_Option_3 | item_id |
+--------------+--------------+--------------+---------+
| 1 | 0 | 1 | 123 |
+--------------+--------------+--------------+---------+
| 1 | 1 | 0 | 456 |
+--------------+--------------+--------------+---------+
| 0 | 1 | 1 | 789 |
+--------------+--------------+--------------+---------+
item_option_1-2 table (this would be used to print the names):
+-----------+--------------+--------------+
| option_id | name | name_es |
+-----------+--------------+--------------+
| 1 | Sub_Option_1 | Sub_Opción_1 |
+-----------+--------------+--------------+
| 2 | Sub_Option_2 | Sub_Opción_2 |
+-----------+--------------+--------------+
| 3 | Sub_Option_3 | Sub_Opción_3 |
+-----------+--------------+--------------+
What kind of structure do I need to spawn these sub options (checkboxes) dynamically?
What about something like this?
Your model has option keys as columns and values as rows. Why have both keys and values be rows? If you don't need complex type-based validation, it should suffice to have a single options table with a one to optionally many relationship to itself to account for suboptions. To enumerate all options and values, just retrieve all rows from the table. If ParentOptionId is null, then it is a base-level option; otherwise it is a suboption.
UML & ER version below.
EDIT: After reading through your question and comments again, I've come up with a more complicated but more robust design for you to consider:
It works like this:
Every user input is an Option. Every option consists of a display text (OptionText), tooltip/subtext/etc (Description), a default and then user supplied value (Value), a value type (ValueType boolean,text, date, etc). It also has a DisplayOrder so you know where to situate it in relation to other Options in its group. Options can also have a parent/child relationship with other Options. You can do the same for the other entities if you want but I did not model that.
Every Option is contained within an OptionGroup with 0 or more sibling Options. OptionGroups are just a collection of one or more related Options. The GroupType field dictates how your form builder needs to treat that group. The most obvious example would be for your radio button groups; each of those would be an OptionGroup and each radio button would be a boolean Option within the OptionGroup. An OptionGroup could just as easily handle a multiple selection checkbox group or just some related text inputs that need a common header text (like a street address).
For further dynamic design OptionGroups are contained within GroupSections, even if there is just one default GroupSection in a form.
Finally, a Form models your final actual UI form and consists of one or more GroupSections.
This should be flexible enough for you to tweak to your liking. What do you think?
Final note: if you are looking into dynamically building your forms in Javascript, check out a few frameworks like X-editable or formly. They take JSON or configuration objects and build out the entire form with validation/etc from there while giving you some hooks for event handling. Chances are you don't need to completely reinvent the wheel unless you want to keep your implementation as simple and specific as possible.

SSRS Calculating Totals

In SSRS I have a report generated from a stored procedure. I have one column that is named "Price" and the report has various groupings (shown below). So because there are so many groupings there are a lot of totals for price. I need to roll these totals up into the parent grouping of TimeRange as an average. This is so I can know the average price of Z product was X. I obviously know that this is done by adding up all those totals and dividing by the amount of totals but I don't know how this can be done in SSRS. Is it possible to dynamically add up all those totals? Or maybe set some kind of global variables to handle this?
EDIT: I described the problem a bit wrong. It seems the main problem is the fact that the price data returns all positive "prices" then the report uses the other columns to define if the price is negative or not(if we bought something or sold something). Since I didn't think there was a way to compensate this through the microsoft code. I Grouped them together based on the rules and multiplied the prices that should be negative by -1. I Now want to figure out a way to take these individual totals and combine them into one Subtotal. It would do this by taking a Sum of the totals. Just doing a straight Sum(Price) doesn't help because that will just get all of the values directly from the query before the report touches them and those values are all positive which throws off the report data.
So i guess there are three solutions here:
1.There is some magical SSRS code that allows me add together data that is outputted from an expression instead of the initial database value and does that dynamically..
2.There is some kind of way to define and assign global variables in the report then I could use some kind of psuedo code to add and subtract data from the variable and then take the average of the total
3.This is currently not possible and I will have to completely rewrite the source data's process or come up with another solution that's not SSRS.
TimeRange
_
| Product
| _
| |
| | Time Unit
| | _
| | |
| | | TransactionType
| | | _
| | | |
| | | | Pay Status
| | | | Price Total Calculated Here [Sum(Price)]
| | | |_
| | |
| | |_
| |
| |_
|
|
|
|_
Reporting Services makes this very easy - in fact, if you were to just use the wizard (table wizard in Report Builder, report wizard in Visual Studio/BIDS), and add all of your grouping fields to the "groups" section, and then enable subtotals, the summing would be done for you, and you could then alter the field using an expression to divide the two summed fields.
Here's a link to some more useful information on grouping and aggregates:
http://technet.microsoft.com/en-us/library/ms170712.aspx
Use the Avg function to get an average of all the values in your grouping:
=Avg(Fields!Price.Value)

SQL schema / query design for horizontally scaled clients iterating through a list

I've got two tables (simplified)
List_To_Action
----------------------------------------------------
| Item_Name | Date_Time_Actioned | Action_Success? |
----------------------------------------------------
And
Action_Records (created by software)
------------------------------------------------
| ID | Item_Name | Date | ... | Action_Success?|
------------------------------------------------
I'm writing a python script that tells a client to iterate through List_To_Action for items that have not yet been actioned.
This would be simple if I had just one client accessing the table:
SELECT * FROM List_To_Action WHERE Date_Time_Actioned IS NULL
However, I will be horizontally scaling and multiple clients will be hitting this list to search for items that have not been actioned, so what I want to know is.
How would I set up the schema / query for this list so that when multiple clients are hitting List_To_Action, they're not pulling out the same items? Pseudo code / pointers are fine.

Displaying a Crosstab Query with Variable Fields in a Subform

Microsoft Access 2010 here. Working with reports (and forms).
I have a crosstab query that transforms (w/ UNION ALL, thank you Bluefeet!) and pivots another "source query" with the purpose of making the results more coherent to the reader. The source query has fields that do not change, but rows that do, as the source query only selects results from the past 30 days; the fields of the subsequent crosstab query are not expected to stay the same upon requery as the rows have become the fields and vice-versa. What I am wondering is how one would display such a crosstab query in a subform as-is; i.e. as a simple reference with no record-dependence.
An example of the variable fields in the crosstab query:
Criteria | 11/26/2012 | 11/27/2012 | 11/29/2012 | 12/6/2012 ...
# Insp | 7 | 8 | 8 | 9
# Passed | 5 | 4 | 5 | 7
# Failed | 2 | 4 | 3 | 2
% Acceptance | 71% | 50% | 63% | 78%
I have successfully tied the crosstab query to a subform "child" for display through it's "Source Object" property, and achieved the desired end-result, but there was the record selection bar which is undesired for a reference, and the option to display it, normally found on forms/subforms is gone on the subform "child."
This leaves me wondering if there is another way to do display crosstab queries in subforms, or if I am looking in the total wrong direction to achieve the task. The report includes a graph based on the source query and below that is to be the crosstab query, displayed purely for reference. Thank you for the help!