Hello I have a question about using LOD For subtraction in tableau.
I have a table with different dimensions such as customer name, sales group, distribution center and measures that I need to work with is subtracting products that was SHIPPED from FORECAST using LOD TO Compute this and get a percentage difference between the two measures using those dimensions.
Can you help?
Let's say you have a measure called Amount. You can get the Total Amount by Customer Name:
{ FIXED [Customer Name] : SUM[Amount] }
And let's say you have another measure called ForecastAmount. You can get that total by Customer Name:
{ FIXED [Customer Name] : SUM[ForecastAmount] }
So if you create two calculations using those formulas, you'll have the basis for your percentage difference. The formula for percentage difference is:
ABS([LOD Amount] - [LOD ForecastAmount]) / (([LOD Amount] + [LOD ForecastAmount])/2)
(and then format that result as a percent, or multiply it by 100).
You can apply the same logic to your other dimensions.
Related
I have a data table with three dimensions and one measure. For each row, I am trying to calculate the percentage of total (calculated by taking the sum of rows) using a calculated field.
As seen in the screenshot attached, For the column titles 'Dec-19' I want the values to be a percentage of current value / grand total (calculated at the bottom as 122,187)
Screenshot of DataTable:
So e.g. for the Column B value of 2000, the Dec-19 column should be (97/122,187) * 100 = 0.079.
I have achieved this by creating a calculated field with the formula: SUM (sales) / MAX ({EXCLUDE (Column B): Sum (sales}), where sales is the measure used in the datatable.
However, upon application of filter on column B, the percentage value changes. e.g. if I select the value 2000 in my filter for column B, I get the percentage as 100%. It seems as if the percentage is being calculated based on only the rows in the filter.
Since you haven't included any sample data, I created some sample data like this, hope this resemble yours.
Thereafter, I built a cross-tab view in tableau, somewhat like yours
If that is the scenario, use a calculated field, say CF like this, instead of yours
([Sales])/
{FIXED [Col1], DATETRUNC('month', [Col3]) : sum([Sales])}
Dragging it in the view
and thus, filtering won't affect your calculation
i know someone has probably asked this but i can't seem to find an answer that works for me.
i have an excel sheet that contains the sales and dates of a company.
i want to calculate the average of the sales made during weekday/weekend receptively, and use that average to calculate any outliers such as a sudden drop increase/decrease in sales.
i have created a calculation to identify between weekday/weekend
IF
DATENAME('weekday', [Date]) = "Saturday"
OR DATENAME('weekday', [Date]) = "Sunday"
THEN "Weekend"
Day Calculation
i have also created a calculation that calculates the average
INT(SUM(
IF [Day] = 'Weekday'
THEN [Number of Records]/22
ELSE
[Number of Records]/8
END ))
Average Calculation
this is my calculation to calculate outliers 20% higher/below the average
[Number of Records] * 1.2 > [Average]
OR
[Number of Records] * 0.8 < [Average]
Outlier Calculation
but it doesn't seem to be working when i put the outlier calculation into "color". the bar chart remains the same
Bar Chart
how do i go about resolving this? is my calculations wrong?
In your graph, the average is calculated at the level of date, for that reason is not working (is always true). To fix this, you have to use Level of Details expressions.
Also, considering you want to calculate the average of the sales made during weekday/weekend, your calculations should use the measure Sales instead Number of Records.
The average calculation would look like this:
{FIXED [Day]: AVG([Sales])}
And the outlier calculation:
[Sales] > 1.2 * [Average] OR [Sales] < 0.8 * [Average]
Wanted Result: Average of the turnover value on days that are between the start and end reference period.
Using Tableau Desktop
Lod expression
The first step is i return the turnover value on days that are between the start and end reference period, and return null otherwise.
Daily Turnover in reference period
IF [Date]>= [Start reference date]
and [Date]<= [End reference date]
THEN [Amount] END
Second Step is to calculate the average across this range of values for each product.
Average Turnover in reference period
{FIXED [Product]: AVG(Daily Turnover in reference period)}
Here a screen shot
The average must be 2331 and not 24.
Really i need HELP.
Thanks.
There are multiple possible approaches, here is one.
Define an LOD calc as Daily_Amount_Per_Product
{ FIXED Product, Date : SUM([Amount]) }
Put Date on the filter shelf and select the range of dates you want to analyze. Put Product on the Rows shelf and put Daily_Amount_Per_Product on the Columns shelf.
At this point you are almost, but not quite done. Since your LOD calc as at a deeper level of detail (has more dimensions in play) than your view, Tableau will perform aggregation to get a result at the same level as your view - which is why you see the word SUM before your field on the Columns shelf. If you want to see the average instead of the sum, change SUM to AVG and you should have your result.
I am trying to calculate average of 2 columns in another column in Tableau but difficult part is grand total is not getting average instead it is the sum of 3rd calculated field.
A B Calculated field
10 5 2
6 3 2
T 16 8 4 (Here I should get 2 instead it is taking sum of column)
Here I am unable to write separate formula for row totals and grand totals, Only one formula (Calculated Field) is allowed and when I am dragging on sheet it is by default aggregating to sum.
Note: I am expert in Crystal and BO but beginner in Tableau.
Update
Code used for LoD
{FIXED [Product Category]: AVG([Sales])}
Below image is what I got after implementation I have tried with 2 columns but the result is same if I use only one column (I am trying to get the average of sales)
You are almost there - the Grand Total by default does a SUM function you just have use the Total All Using --> Average option.
Output : Level wise SUM(Profit) later averaged across columns and rows. (Show Column Grand Total & Show Row Grand Total active)
Update: Answering the question below. To get the Row-wise avg (which is Cat1-vag in this case) you could just drop the measure and change it to AVG(). Since you needed in a Calculated Field you could use a Simple FIXED LOD. You can also uncheck aggregated measures from Analysis dropdown and have no Dimension in column or row like unlike what this example shows and still get three different averages. Cheers.
{FIXED [Cat1]:AVG([Profit])}
Check out this very smart work around from Joe Mako.
https://community.tableau.com/thread/112791
create a calc field like:
IF FIRST()==0 THEN
WINDOW_AVG(SUM([Sales]),0,IIF(FIRST()==0,LAST(),0))
END
duplicate your Category field
place "Category (copy)" on the level of detail
set the compute using for the calc field pill to use "Category (copy)"
The window function in the calculated field only takes into account what's in the view, and aggregate based on those number.
I'm having an issue with tables calculations in tableau. I've got sales per manager and the target. I wanna have a calculation of the targets achievement.
That's what my data looks like and the percentage I wanna get:
Unfortunately, Tableau sums up the percentage and gives me the following results:
Target columns is a calculated field. E.g.
IF [Manager Name] = "Manager 1" THEN "190000"
The % columns is a calculated field and calculated as the following:
FLOAT([Profit]) / FLOAT([Target])
I tried to play with Table Calculations but it never worked.
You are right in that a table calculation would help solve your issue. As you have the % field now, Tableau is just summing the field for each manager to get your subtotal. To get Tableau to calculate the subtotal smartly, as you would expect, you need to modify your % field formula.
Your way: Calculate Percentage for each manager and then SUM for subtotal
Fixed Way: Indicate to Tableau that you want the field to be calculated by summing all profit values first in the partition (Location) and then divide to get the percentage. In this case (330000/532000).
You can modify your % field to look something like the following:
WINDOW_SUM(FLOAT(SUM([Profit])))/WINDOW_SUM(FLOAT(SUM([Target])))
See the below thread for some more information on how the windowing functions can help with aggregate calculations
https://community.tableau.com/thread/200670