I'm trying to create classifications based on date that are overlapped between each other.
Taking "Sample - EU SuperStore" as a reference, I want to do the the following:
Show measures as rows, for example Sum of Profit and sum of Sales
Create two columns: 2016 and Q1 2016.
Output Example:
+-------------+---------+---------+
| Measures | 2016 | Q1 2016 |
+-------------+---------+---------+
| sum(Profit) | 49,544 | 3,811 |
| sum(Sales) | 484,247 | 74,448 |
+-------------+---------+---------+
Is there a way to achieve this without changing the underlying data model?
I've tried using parameters but at the moment of putting to parameters together they are consider as the same column with different "hierarchies". See image below (Parameters are called 1 and 2)
If your periods of interest only overlap because one of them is a total of some of the others, you may be able to just use turn on the totals and sub totals of interest from the menu.
Otherwise, you can define calculated fields that select your values of interest for some records, and null for other records. Some people call those conditional fields or conditional calculations. Since aggregation functions like SUM(), MAX() ignore null values, you can then use those fields as measures to get the effect you want.
For instance, if you create a calculated field called [Sales During Promotion] as
If [Date] >= #2/15/2020# and [Date] <= #3/15/2020# then [Sales] end
Then SUM([Sales During Promotion]) will be the sum of all sales that fell within the specified period.
The last trick to understand the calculated field above is to know that the default behavior if there is no else branch specified is to return null.
Related
I have a PnL table with 3 columns. date, region, product.
I'm trying to group all PnL rows by region and product. One way that i've tried is to sum by region and product as following
select PnL : sum(PnL) by region, product from table where date within (d1;d2)
The issue I have is unexpected results. For a given date range (d1;d2) I'm getting the results I'm expecting. However for date range (d1;d2+1) I'm getting 0 everywhere.
I checked the data availability on the d2+1 and data is already available on that day.
Please note that the server is stateless and it is not possible to use intermediate results in variables.
What is the best way to achieve a grouping sum in KDB?
I am new to Tableau visualization and need some help.
I have a set of shipping lanes which have whole numbers values based on the duration for the shipment.
Ex:
| Lane Name | 0 Day | 1 Day | 2 Day | 3 Day | 4 Day |
| SFO-LAX | 0 | 30 | 60 | 10 | 0 |
| JFK-LAX | 0 | 10 | 20 | 50 | 80 |
For each Lane Name, I want to return the column header based on the max value.
i.e. for SFO-LAX I would return '2 Day', for JFK-LAX I would return '4 Day', etc.
I then want to set this as a filter to only show 2 Day and 3 Day results in my Tableau data set.
Can someone help?
Two steps to this.
The first step is pretty easy, pivot your data. Read the Tableau help to learn how to PIVOT your data for analysis - i.e. make it look to Tableau as a longer 3 column data set with Lane, Duration, Value as the 3 columns. Tableau's PIVOT feature will let you view your data in that format (which makes analysis much easier) without actually changing the format of your data files.
The second step is a bit trickier than you'd expect at first glance, and there are a few ways to accomplish it. The Tableau features that can be used for this are LOD calcs, table calcs, filters and possibly sets. These are some of the more powerful but complicated parts of Tableau, so worth your time to learn about, but expect to take a while to spin up on them.
The easiest solution is probably to use one of the RANK() function - start as a quick table calc. Set your partitioning and addressing as desired so that the ranks are computed for the blocks of data that you desire - say partitioning on Lane and addressing or computing by Duration. Then when you are happy with the ranks you see, move the rank calculation to the filter shelf and only display data where rank = 1.
This is a quick solution once you get the hang of it, but it can get slow for very large data sets since the rank calculations are done on the client side, requiring fetching all the data that you end up not displaying. If performance becomes an issue, you might want to look at other solutions to do more of the calculations server side - possibly using LOD calcs or analytic aka windowing queries invoked from custom SQL
I am having a difficult time aggregating the lowest level of a row group with SUM while aggregating all higher row headers by MIN.
My data is like this structured in a group like this:
Assembly
Parent
Child
Orders
Inventory
And an example of my dataset might look like:
Assembly | Parent | Child | Supply Type | Available Quantity
A1 | P1 | C1 | Orders | 0
A1 | P1 | C1 | Inventory | 50
A1 | P1 | C2 | Orders | 100
A1 | P1 | C2 | Inventory | 0
A1 | P2 | C3 | Orders | 50
A1 | P2 | C3 | Inventory | 100
I want to SUM the measures in the Supply Type rows when I collapse up to the Child row group, but then to show the MIN when I collapse to the Parent and Assembly row groups. For instance, if I collapse at the Child level I want to SUM and have C1 to show a total of 50 and C2 to show a total of 100, but when I collapse at the Parent level I want to see the MIN and have P1 show 50 and P2 show 150.
I was able to partially achieve what I am trying to do with:
{ INCLUDE [Child],[Parent],[Assembly] : MIN({ EXCLUDE [Supply Type] : SUM([Available Quantity])})}
But now at the lowest levels the Order and Inventory measures show the same numbers (which is not accurate) since the EXCLUDE function is essentially ignoring the categories at the Supply Type row level.
Ok, briefly, my recommendation is to (slightly) alter your approach. There are ways to literally do what you say you want, but they are more complicated and brittle than I think most people would want, just for the convenience of controlling by hitting + or
- to expand and collapse levels (not to mention a bit confusing to the user). Especially when there are alternatives that are simpler and likely more reliable.
Here is one alternative method using parameters and calculated fields -- which is a pretty general approach for many things in Tableau.
Define a parameter that specifies how many levels of your dimension hierarchy you wish to display. Call it, say, Display_Level or whatever makes sense to you. Give it the data type string, and provide a list of allowable values, say "Assembly", "Parent" etc.
Show your parameter control and choose how you wish it to look, say a combo box or radio buttons.
Define one calculated field to be the displayed dimension as follows, and put on the Rows shelf or others as desired.
case [Display_Level]
when "Assembly" then [Assembly]
when "Parent" then [Assembly] + " - " + [Parent]
when "Child" then [Assembly] + " - " + [Parent] + " - " + [Child]
...
end
Define another calculated field to be the displayed measure as follows, and put on the Columns shelf or others as desired.
case [Display_Level]
when "Assembly" then Min([Quantity])
when "Parent" then Min([Quantity])
when "Child" then SUM([Quantity])
...
end
This first draft may not be exactly what you want, but the approach can easily be extended. You are just using a parameter to control the display detail instead of clicking on the + or - next to a field name.
If you don't like the full names on the dimensions separated by dashes, then you can create multiple dimension fields to serve as labels, one per level, and have them either return the corresponding field or null depending on the parameter setting. For example, the Parent Label field could be defined as if [Display_Level] <> “Assembly” then [Parent] end Do something similar for the others. Then put all your “Label” fields on the viz to create row or column headers as desired. This will behave much like expand/collapse except that you control the detail using the parameter. There are several ways to get the Null to not display.
If your measure calculations are more complex than MIN() or SUM() - say if they use LOD calcs to rollup values first - then just modify your measure calculation.
using SSRS 2008 R2 here.
I've been able to get a similar layout to work with a regular tablix, where I get each group header to fall on top of each other in the same column by adding a row within that group, however I need to use a Matrix because of a dynamic column (month below). When I try to add another row, it only adds a row where the monthly data starts, not in the headers. So the headers stay in their each column. In trying to keep the example as easy as possible, I'm trying to do something like this (Store theme).
STORE NAME | MONTHS
STATE | SALES
TOWN(S) | SALES
which woudl look something like this in a Matrix
WALMART JAN FEB MARCH etc....
TEXAS | 3000 2000 6000
HOUSTON | 1000 500 2500
AUSTIN | 2000 1500 3500
I've only been able to produce something like this where each group is a seperate column:
STORE | STATE | CITY | JAN | FEB | MAR |
WALMART | TEXAS | HOUSTON | 1000 | 500 | 2500 |
| AUSTIN | 2000 | 1500 | 3500 |
Again, I've been able to get a regular Tablix formatted like this, but a Matrix I'm struggling with. Can anyone help me on how to do this? Thank you in advance!!
It is possible using a tablix/matrix and adding some special grouping settings.
Add a tablix with the City field in Row Groups pane:
Right click the City group, select Add Group / Parent Group. Choose State and set Add a Group Header
Delete the left most column (State column added in the previous step).
Note the group is still present.
Right click the STATE group and add a Parent Group as step 2. In this case choose STORENAME
Again delete the left most column (Store Name column added in the previous step)
You will get the following tablix.
Delete the first row
Set the Fields using the Row Group hierarchy order. STORENAME/STATE/CITY
Right click the first cell in the next column and add a group / Column Group / Parent Group. Choose MONTH in group by.
Delete the first row.
Set SUM(Fields!Sales.Value) in the next cells in the same column.
After these steps you will get a tablix like this in design window.
It should produce:
Let me know if this helps.
With tableau I am able to act on some data tables to get to a text table that I would like to treat as a table from scratch to do further aggregation. You will see from my example what I actually want to do, but acting on a text table as if it were a brand new table seems to be one solution if possible. I am open to other solutions to the same problem if you have any.
Say I have two tables.
Table A
Date | Purchases
'2014-05-02' | 5
'2014-05-03' | 6
Table B
Date Bucket | Bake Rate
0-1 Month | .20
2-3 Month | .50
First I created a calculated field for Table A to put each line item date into the corresponding date bucket by figuring out how much time has passed from a certain date and called it Date Bucket. Then I made a relationship between Date Bucket in Table B and the newly formed dimension in Table A also called Date Bucket. From Here I could essentially join on date bucket and for each line item get a Bake Rate from table B.
Then I divide each purchase by the corresponding bake rate as determined by how Age Bucket.
So I ended up with a text table like the following.
Date | Age Bucket | Purchases | Baked Purchases
'2014-05-02' | 0-1 Month | 5 | 25
'2014-05-03' | 0-1 Month | 6 | 30
Ideally, from here I'd like to be able to get the sum of the baked purchases and aggregate by whatever other dimensions I have. For example here, get the sum of baked purchases by month.
Any Ideas?!