tableau aggregate data based on dimension - aggregate-functions

I am having a problem in Tableau, hopefully someone can help me and
is very much appreciated!!
A simplifiend example of a problem I can't fix in Tableau:
Payment Customer Amount
1 BMW 20000
2 VW 30000
3 BMW 1000
4 VW 5000
5 VW 6000
This has to be aggregated on the Customer level and has to look like this:
Customer Amount
BMW 21000
VW 41000
This is for 10.000 customers..
Thanks in advance!
Tim
I want to take the average/mean/max for each year (pool cut-off date) in order to compare the years.
In R I always saved the new dataframe, but here this seems to be different.
Thanks,
Tim

Let me know if you were going for something else, but if you are trying to simply visualize the data you can do this:
EDIT:
To create a calculated field go to: Analysis > Create Calculated Field, or select Create Calculated Field on one of the Data window title menu.
You can call that one SumAmount and the calculation would be:
sum([Amount])
Here is an example of what you can with calculated fields:
Here is a good guide: How to Create a Calculated Field

Sum() is one of Tableau's built-in aggregation functions, so there is no need to write a calculated field if that's all you're doing. Just drag the [Amount] field on to (say) the text shelf and select Sum() as the aggregation. Then put [Customer] on the row shelf.
Sum() is efficient, and performed on the database server only sending back the results to the client. So if you are summing a million rows, only the answer needs to be sent over the wire. Of course, if you are grouping by a dimension so that half your dimension members have only one row, you'll still be sending back lots of data.
If your calculation is more complicated, emh is correct about where to start making calculated fields.

Related

Blending 2 dimensions and 2 metrics into 1 dimension and 1 metric

I have a UA account and a GA4 account.
In UA I have:
Dimension: Event Category
Metric: Unique Events
In GA4:
Dimension: Event name
Metric: Event count
Is there a way to blend data in a way that I have 1 dimension (event category OR event name) and 1 metric (unique events OR event count)
I'd really need to come to 1 single dimension and 1 single metric.
Thanks in advance.
Data studio supports blending data which means to join two or more datasets. Here you ased for appending data which is in SQL called an UNION ALL.
How to union two dataset in Data Studio
First generate a Google Sheet document with the numbers 0 and 1:
Add this sheet to Data Studio and take care that the column is interpreted as a number:
To each of your datasets from UA and GA4 please add a calculated field dummy with
the formula 0 and in the 2nd datset with the formula 1.
Blend these dataset together:
Since the column test on the left dataset has the value 0 and 1, the other two datasets are unioned.
To combine the two dimensions, please add the + twice:
and enter following formula there
case when test=0 then name else name2 end
and a formula for the metric (counts and events columns) as well:
case when test=0 then counts else events end
Rather than Blending, if you want to "UNION" two separate tables, currently the Google Data Studio does not support it, however I recommend you to use this tool called Windsor AI, This platform will allow you to see all different kinds of Data Sources and do whatever operations you want with them in one place.
Suppose, I want data from Google Analytics, I'll simply choose the data source from the account I want to pull the Data from..
1
From there you can preview your Data and then procced to pull it and from Multiple Tables like here
2
You can then export it to any Data Platform you want
3
Hope this Helps..
P.S. This is a genuine problem that Data Studio has, although Data Studio is relatively new, it lacks a lot of features that can enable it to be a viable platform amongst it's competitors.

Tableau graph average and sum

I have transactional data for a sales team showing the transaction amount per transaction, the sales person for that transaction, his team and his salary. Every row denotes a unique transaction (please refer image). I need to make a team-level graph which shows the correlation between the salary they are paid and the revenue they generate for the company i.e. a simple stacked bar chart with salesTeam name on X axis and amounts on the y axis with every bar representing the total salary and total revenue(Amount) for a team.
In the example I've highlighted team 'Central', for which the salary paid is 25k (10k for salesperson A + 15k for salesperson B) and the revenue they make for the company is 430k. Please note that the salaries for some salespersons may be missing (eg. for E). The issue I'm facing is that sum(Salary) adds up the salaries for every row, so for salesperson A it becomes 20k instead of 10k. I tried avg(Salary) but that doesn't work as Tableau calculates the average for the entire column instead of average per salesperson. How can I solve this issue?
Thanks
Here you have a level of detail problem. Basically, Tableau will calculate a formula at the level of detail of the visualisation, so if salesperson is not in your view it will roll up the equation to calculate at the highest level. This is great when you want a dynamic calculation but that doesn't sound like what you are trying to achieve.
Your best option would be to aggregate the data into Tableau so you only have 1 line per sales person with a total of their revenue for all transactions. This would avoid the complexity of the calculated field (and make Tableau perform better).
However, if this is not possible the good news is the answer is a Level of Detail expression (i recommend doing some reading on this if you havent come across before). Basically, you tell Tableau at what level you want the calculation at.
If I understand you want to calculate the ratio of transaction amount and salary paid for each team.
So create a calculated field as follows:
{ FIXED [Team]
: sum(([Amount]))/
(sum({ FIXED [Sales person]:
AVG([Salary])}))
}
What this does is calculates for each team the ratio between the amount and the salary. The use of the second fixed equation that is nested within it (Salesperson) ensures that the salary is not summed for the number of transactions of a salesperson.
Using this I got a result of 17.2 for Central. Is this what you would expect? Do you need a way to account for salaries that are not known?

Frustrating Formula - Help Needed with Google Sheets formula/method

I am struggling to come up with a formula that fits certain criteria and was hoping someone with a better math brain than me might be able to help. What I have is a Google Sheets based tool that determines how much a someone has purchased of a product and then calculates the amount of times a special additional offer will be redeemed based on the amount spent.
As an example, the offer has three tiers to it. Though the actual costs will be variable for different offers let's say the first tier is gained with a $10 purchase, the second with a $20 purchase and the third with a $35 purchase (the only real relationship between the prices is that they get higher for each tier but there is no specific pattern to the costing of different offers). So if the customer bought $35 worth of goods they would get three free gifts, if they bought $45 worth they would get 4 and then an additional spend of $5 (totaling $50) would then allow them to redeem 5 gifts in total. It can be considered like filling a bucket, each time you hit the red line you get a new gift, when the bucket is full it's emptied and the process begins again.
If each tier of the offer was the same cost (e.g. $5, $10 and $15) this would be a simple case of division by the total purchase amount but as there is no specific relationship between the cost of the tiers (they are based on the value of the contents) I am having trouble coming up with a simple 'bucket filling' formula or calculation method that will work for any price ranges given to it. My current solution involved taking the modulus, subtracting offer amounts from the purchase amount etc. but provides plenty of cases where it breaks . If anyone could give me a start or provide some information that might help in my quest I would be highly appreciative and let me know if my explanation is unclear.! Thanks in advance and all the best
EDIT:
The user has three tiers and then the offer wraps around to the start after the initial three are unlocked once, looping until the offer has been maxed out. Avoiding a long sheet with a dynamic column of prices would be preferable and a small, multicell formula would be ideal
What you need is a lookup table. Create a table with the tier value in the left column, and the corresponding number of gifts for that tier value in the right column. Then you can use Vlookup to match the amount spent to correct tier.
I am not quite sure about, everything into one entire formula(is there a formula for loop and building arrays?)
from my understanding the tier amounts are viable, so every time you add a new tier with a new price limit then it must be calculated with a new limit price number...wouldn't it be much easier to write such module in javascript than in a google sheet? :o
anyways here is my workaround, that may could help you to find an idea
Example Doc
https://docs.google.com/spreadsheets/d/1z6mwkxqc2NyLJsH16NFWyL01y0jGcKrNNtuYcJS5dNw/edit#gid=0
my approach :
- enter purchases value
-> filter all items based by smaller than or equal "<=" (save all item somewhere as placeholder)
-> then decrease the purchases value by amount of existing number(max value) based on filtered items
-> save the new purchases value somewhere and begin from filtering again and decreasing the purchases value
(this needs to be done as many times again, till the purchases is empty)
after that, sums up all placeholder

dimensional data modelling design - Data warehouse

I am having
dimension tables
item (item_id,name,category)
Store(store_id,location,region,city)
Date(date_id,day,month,quarter)
customer(customer_id,name,address,member_card)
fact tables
Sales(item_id,store_id,date_id,customer_id,unit_sold,cost)
My question is if I want to find average sales of a location for a month Should I add average_sales column in fact table and if i want to find sales done using the membership card should I add corresponding field in fact table?
My understanding so far is only countable measures should be in fact table so I guess membership_card should not come in fact table.
Please let me know if I am wrong.
No, you should not add an average sales column to your fact table, it is a calculated value, and is not at the same "grain" as the fact table.
Your sales fact table should be as granular as possible, so it should really be sales_order_line_items, one row per sales order line item.
You want to calculate the average sales of a given store for a given month...?
First, by "sales" do you mean "revenue" (total dollars in) or "quantity sold"?
Average daily revenue?
Average monthly revenue, by month?
If you have the store id, date, quantity sold (per line item) and unit price, then it's pretty easy to figure out.
You Should not add aggregate columns In the same fact table. The measures in the fact table should be at the same grain. So if you want aggregate metrics, build a separate fact table at the required grain.
So, I might have a fact aggregate table named F_LOC_MON_AGG which has the measures aggregated at location and month level.
If you do not have aggregate tables, modern business intelligence tools such as OBIEE can do the aggregation at run time.
Vijay

Calculation of Cost Amount Physical

How does AX calculate the Cost Amount Physical on inventory transactions (Inventrans table)?
When posting packing slip in purchase order, transaction records are created in the Inventrans table, this table has a field (CostAmountPhysical)
How does AX calculate the value of this field?
Sometimes this value is different to the net amount calculated in each item of the purchase order?
The CostAmountPhysical field is calculated in the InventMovement.updateLedgerPhysical method.
There is no easy explanation of how and why it is calculated. Go and have look in the code.
Please update you cross reference, this simplifies questions like this one enormously.

Resources