Tableau : Average Not working as Dimensions not match between Filtered values - average

Issue: When more than one state is selected in Filters the average is not calculated as expected. For a single state, it is working fine.
The data source contains the following Dimension and Measures -
Dimension: SKU, Country, State, Run Date
Measure: Profit
Dataset is as follows -
Country
State
Run Date
SKU
Profit
USA
Texas
2022-06-01
Table
20
USA
Texas
2022-06-01
Chair
30
USA
Ohio
2022-06-01
Table
5
USA
Ohio
2022-06-02
Table
10
Expected Result of Average (Country and State are used as Filters. Profit is used in values)-
SKU
2022-06-01
2022-06-02
Table
12.5
Chair
15
5
Current Result of Average (Country and State are used as Filters. Profit is used in values)-
SKU
2022-06-01
2022-06-02
Table
12.5
Chair
30
10
I have tried Window_AVG and used SUM and COUNT in the Calculated field but the results are not as expected.
Kindly help with a solution to solve the Averaging issue. Thanks a lot for the support.

Related

Google Sheet - calculating attendance from moving date range

Good day folks, we have a Google Sheet with training attendance. We are meeting on weekly basis and calculate attendance from the past four months, last 36 month and historical total.
Situation: Currently, we calculate the attendance by assigning 2 (double training)/1 (normal training)/0 (canceled training) to the value of the training and attendee (2 on double, 1 on normal, 0 when absent) - and get attendance percentage by comparing the person's points sum to that of the trainings during the given period (4 months, 36 months, total).
Issue: The problem is that every time we add a training (new row in the tab), we need to manually change date range in the 4 month calculation and end date in the 36 months. I would love to automate this process that every time we add a new column, we would not have to change the date range.
Cells:
C4 = maximum points available per trainings in the last 18 months
D4 = maximum points available per trainings in the last 4 months
C5 and below = user's attendance in the past 18 months (his points generated in that timespawn/total available points*100)
D5 and below = user's attendance in the past 4 months (his points generated in that timespawn/total available points*100)
E3:3 = cells with dates when we have trainings
E4:4 = points awarded per that specific training
E5:5 and below = points gained by the member per attendance
Question: is there any way count a number of training points gained in the past 4/18 months by a specific person?
Thank you kindly
try:
=SUM(FILTER(E5:5; E$3:$3>=TODAY()-120; E$3:$3<=TODAY()))/D$4

Split and merge columns in Tableau

I Know how to split the country column into multiple columns(Using custom split I split them on the comma's) but I am not sure how to merge them like shown below(What I want). Any help is greatly appreciated
**What I have**
ID Type Country
1 TV Show USA, UK, Spain, Sweden
2 Movie USA, India
3 Movie USA
4 TV Show Bulgaria, USA
5 Movie Sweden, Norway
6 Movie UK, USA
7 TV Show Germany
8 TV Show India
9 Movie USA, India
10 Movie USA
**What I want**
USA
UK
Spain
Sweden
USA
India
USA
Bulgaria
USA
Sweden
Norway
UK
USA
Germany
India
USA
India
USA
It's actually something you can do in the datasource pane, even though it may not make much sense "inside" Tableau for "data handling".
As you said the first step is splitting your Country column; doing so, for each row you will get N columns where N equals the number of country for the row having the highest number of countries (4 in your example).
Rows having just 1 country will have just the first column with a value and the rest will be null value columns.
Once you have done the first step, you need to pivot your data selecting those N columns, right-click and select pivot.
Doing that you will get N*M rows where N is the maximum number of countries per original row (4) and M is the number of your original rows (10).
Since, as said before there could be null values, the final step should filtering out all "new rows" having null values.

A ratio measured within one dimension shown across another dimension

For the sake of the exercise, let's assume that I'm monitoring the percentage of domestic or foreign auto sales across the US.
Assume my dataset looks like:
StateOfSale | Origin | Sales
'CA' | 'Foreign' | 1200
'CA' | 'Domestic' | 800
'TX' | 'Foreign' | 800
'TX' | 'Domestic' | 800
How would I show the percentage of Foreign Sales, by State of Sale, but each State is a line/mark/bar in the visual?
So for CA, the Foreign Percentage is 60%. For TX, the Foreign Percentage is 50%.
This is what Tableau was born to do!, and there are a lot of great ways to visualize this type of question.
Use a Quick table calculation called "Percent of Total" and compute that percentage according to each State. In the picture below, "StateofOrigin" is in Columns, and "Sum(Sale)" is in Rows, I compute using Table (Down).
You can also graph the raw sales numbers in addition to displaying the text percentage to gain additional context about the number of sales between states.
Finally, if you've got a lot of states, it can be cool to plot it out on a map. You can do this by creating a calculated field for percentage and then filtering out the domestic sales.
Field Name: Percentage
SUM([Sale])/SUM({FIXED [StateofOrigin]: SUM([Sale])})

Tableau - weekly average from daily data

Using Tableau 8.1.
Daily data like this:
Date Sales
1-1-14 $5
1-2-14 $2
...
6-15-14 $15
Which can be aggregated to weeks of course
Week 1 $15
Week 2 $12
Week 3 $10
Week 4 $13
etc.
I would like to get the weekly average of each month
So like this:
Weekly Average
Month 1 (weekly average of the weekly total sales) ($15+$12+$10+13)/4 = 12.5
Month 2
Month 3
Does that make sense? If ou simply put "average" in the tableau table, it gives the average daily value PER WEEK (or month) < - I don't want that. I want the average of the weekly totals per month.
Quite simple, actually.
Create these calculations
Unique Weeks = COUNTD(DATEPART('week',[Date]))
Weekly Average = sum([Sales])/[Unique Weeks]
Then simply report Weekly Average x Month (or Quarter or Year, etc.)
(Note: Some weeks have < 7 days).
This can be done very simply with one calculated field.
WINDOW_AVG(SUM([Sales]))
Then drag your Date pill onto the rows shelf twice, one aggregated to day, the other to week. Make sure pills are set to discrete (blue) and drag your Sales measure onto the shelf, also as discrete.

How to sample from KDB table to reduce data before querying?

I have a table of tick data representing prices of various financial instruments up to millisecond precision. Problem is, there are over 5 billion entries, and even the most basic queries takes several minutes.
I only need data with a precision of up to 1 second - is there an efficient way to sample the table so that the precision is reduced to roughly 1 second prior to querying? This should dramatically cut the amount of data and hence execution time.
So far, as a quick hack I've added the condition where i mod 2 = 0 to my query, but is there a better way?
The best way to bucket time data is with xbar
q)select last price, sum size by 10 xbar time.minute from trade where sym=`IBM
minute| price size
------| -----------
09:30 | 55.32 90094
09:40 | 54.99 48726
09:50 | 54.93 36511
10:00 | 55.23 35768
...
more info http://code.kx.com/q/ref/arith-integer/#xbar