My sheet has measure names divided by ops managers and managers filtered to show values only for current week. What I need is to make new column for each of the measures to show values for previous week and then make %diff. I have seen solutions by putting week in row but is it possible this way somehow?
What I tried:
LOOKUP(sum([missed hours]),-1) (shows values from previous row)
{ FIXED DATEPART('week',[metric_date]),[ops_login_name],[supervisor_login_name]:sum([missed hours])} does nothing, same values as normal
I even tried separate calc field DATEPART('week',[metric_date])-1 that shows previous week number and then { FIXED [previous_week],[ops_login_name],[supervisor_login_name]:sum([missed hours])}
You can do this by filtering for the desired week in the Measure Value and not in the filter shelf. Create two boolean expressions that isolate your week.
Is this week? : datetrunc('week',{max([metric_date])}) = datetrunc('week',([metric_date]))
Is last week? : dateadd('week',-1,datetrunc('week',{max([metric_date])})) = datetrunc('week',([metric_date]))
Then create week specific measure values with sum(if [Is this week?] then [total_miss_cnt] end)
Repeat for previous week and then you can do a % diff. Make sure to remove and date filtering from the filter shelf.
Related
]Difference and percent Difference must be calculated.
I cannot do Apr20-MAy20 because it is not always the same. I need to show the current month and previous month
So I did a relative filter to just show the current month and previous month.
So the difference of two columns should automatically change when the month changes.
Now how do I get the same month of prior year, how do I filter ?
I also need to calculate the difference of current year same month and previous year same month.
Thank you in advance for any help!
When I do table across difference, the difference value is overwriting the existing May and Apr month values as the below screen shot, how to show the difference in another column
Currently:
Below is Expected:
Sounds like you should create a custom filter for the dates. You want:
This month this year
This month last year
Last month this year
There are a number of ways you could do this. I'll give one example and will assume there aren't any future dates in your data set.
[DateFilter]: DATETRUNC('month',[YourDateField])>=DATETRUNC('month',DATEADD('month',-1,TODAY())) OR DATETRUNC('month',[YourDateField])=DATETRUNC('month',DATEADD('year',-1,TODAY()))
Put the to the filters shelf, set to True, and it should keep the months you want.
Then you can just use the standard table calculations to calculate Difference and Percent Difference.
Note, the formula isn't tested, just typed directly into here, let me know if it doesn't work
Based on your comments look at creating separate calculations for to YoY / MoM / etc calculation. That also means creating calculated fields to isolate the Current Month, Previous Month, etc.
For example, the current month:
[isCM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',TODAY())
The previous month:
[isPM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',DATEADD('month',-1,TODAY()))
Then month on month, something like:
[MoM]: (SUM([Measure])*INT([isCM]))/(SUM([Measure])*INT([isPM]))
To make your table check this article about using the placeholder technique to create tables in Tableau
I want to get number of months user selected using Relative Dates Filter?
If user entered "Last 3 Months" then I wants to get number of days for 3 months to use these days in another calculated field.
Calculated field which is using this is as follows.
([Total Sale within Entered Date]/[Number of Days])*365
which returns me predicted sales for the whole year.
Here, [Number of Days] is the filter which I am using. Picture added for Relative Dates filter I am using.
Screenshot of Relative Date Filter:
You need to create a calculated field that works out the number of days in the data.
Something like datediff('day',min([dates]),max([dates])) if data is present for all the days in the time period will work. This calculation will dynamically give you the number of days between the first and last date in the [dates] field for whatever data is selected by the filter (so won't be precise if not all the possible dates are represented in the dataset).
As you can see from the picture above I am trying to add new column and to calculate the difference between =2014-2017.
Is there any way to make this because Tableau's option "Table Calculation" doesn't play role for me.
Working out the difference between the first and last periods with table calculations:
First you need to get minimum year's values (i'm calling the field "Min Year Select"):
IF DATETRUNC('year',[Order Date]) =
{FIXED: MIN(DATETRUNC('year',[Order Date]))}
THEN 1 END
The above field named Min Year Select is saying that it should return a 1 if the year of the order date is the minimum year in your date range
Now we are flagging the smallest years, we can create a field to get the values (i'll call this "Min Year Segment"):
IF SUM([Min Year Select]) >= 1 THEN [Sales] END
Here we're saying that if the year is flagged as the smallest (as classified by the previous calc field we made), then get the value
But before we can compare the two values, you have to work out the number of time periods between the min and current year so that the difference calculation lookup field is comparing the right values (i'll call this "Number Years in Range"):
{FIXED [Segment]: COUNTD(DATETRUNC('year',[Order Date]))}
What we're doing is fixing the query at the category level (segment), think of this as removing the date pill from your report, then performing a calculation. Here it's COUNT DISTINCT years. So if a segment has data for 2011,2012,2013; then the query returns 3
We can now get the difference between your latest and your minimum Segments (called: "Difference from First Last Segment"):
[Segment] -
LOOKUP([Min Year Segment],
-1*(Number Years in Range)-1)
Firstly we get the first year's sales for each segment (Min Year Segment will be null for all years that aren't the first, so we need to lookup the first by going backwards by the number of years in our range:
We do -1 * because we want the lookup to lookup backwards, then we add in ("Number Years in Range" - 1) because we want to lookup to the period that had the earliest data. We do minus one so we're excluding the current year/latest year in your dataset
This is a lot to digest, I think it's easier to present as a picture too:
Here we calculate the difference between the first and last month, with the value in the last month
If this helped or you have any more questions, please vote on my answer/let me know
Could someone please explain me creating BINS based on Weekdays in Tableau? I tried creating different Calculation Fields but it won't work
You're working too hard.
Tableau already knows how to bin values by dates at many levels of granualarity: such as year, month, day, weekday, hour etc. So you don't need to create a new field to bin dates by the day of the week. (creating bins is not difficult, it's just already available in this case)
Just put a discrete (blue) date or datetime field on a shelf. You'll see the date level of granularity displayed like, say, YEAR(MyDateField) with a leading plus sign.
You can either
click on the plus sign to drill down by adding a second level, say MONTH(MyDateField)
or
right click on the field to select the date level of granularity you want
Alex's Answer is exactly correct, Tableau will perform the operation automatically. What is great about is that you can select various formats (Full day name, number, 1 letter or 3 letter day etc.).
However if you absolutely need to you can used this formula:
datepart('weekday',[Date])
to give you the 1 (Sunday) to 7 (Saturday) value if you need it for something other reason, say another calculation.
I need to filter my query with different time intervals like that:
...
where
date >= '2011-07-01' and date <='2011-09-30'
and date >='2012-07-01' and date >='2012-09-30'
I suppose such code is not good, because these dates conflicts with each other. But how to filter only these two intervals, skipping everything else? Is it even possible? Because if I query like this, I don't get any results.I tried to use BETWEEN, but it does same thing.
I bypassed this by extracting quarters from years and calculating only third quarter. But then other quarters sum is showed as zero and I can't ignore these rows that have sum column with zero value. I tried to filter where price > 0 (column where sum goes), but it says that column do not exist. So I put it whole FROM under '('')' brackets to make it calculate sum before where clause, but it still does give me error that such column do not exist.
Also if you need to see query I have now, I can post it, just tell me if it is needed.
I want to do this, because I need to compare third quarter of two different years (maybe I should use another approach).
You're not going to get any results because you can't have a date that's both within 7/1/2011 through 9/30/11 and after 7/1/2012 and after 9/30/12.
You can have a date that is either between 7/1/20122 and 9/30/2011 or between 7/1/2012 and 9/30/2012.
SELECT col1 FROM table1
WHERE date BETWEEN '7/1/2011' AND '9/30/2011' OR date BETWEEN '7/1/2012' AND '9/30/2012';