Calculated Field in Tableau - one measure to represent various date calculations

0 votes

I'm curious if it's feasible to build a single 'calculated field' that can be used as a Tableau dimension that has the following:

Recent Month (Dec 2022) Prior Month (Nov 2022) Recent Month - Year Ago (Dec 2021) YTD (Jan 1-Dec 31, 2021) Prior YTD (Jan 1-Dec 31, 2022

I tried to utilise an IF THEN statement, but the order of operations won't 'bag' November 2021 data into the two categories that are required. Do you have any suggestions? Is it even feasible to do so?

This is my take on it (based on data from superstores):

`If DATETRUNC('month',[Order Date]) = 
DATEADD('month',-2,DATETRUNC('month',TODAY()))
THEN 'Prior Month'
elseif DATETRUNC('month',[Order Date]) = 
DATEADD('month',-1,DATETRUNC('month',TODAY())) then 'Most Recent Month'
elseif DATETRUNC('month',[Order Date]) = 
DATEADD('month',-13,DATETRUNC('month',TODAY())) THEN 'Most Recent Month a Year ago'
ELSEIF [Order Date (copy)] <= DATEADD('year', -1, [Order Date (MAX)])
AND [Order Date (copy)] >= DATE("1/1/"+ STR(YEAR([Order Date (MAX)])-1))
THEN 'PYTD'
elseif [Order Date (copy)] <= [Order Date (MAX)] AND DATETRUNC("year", [Order Date (copy)]) = DATETRUNC("year", [Order Date (MAX)])
THEN 'YTD'
END
Mar 11 in Tableau by Vaani
• 5,040 points
18 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Tableau

0 votes
1 answer

Is it possible to join tables on the basis of some calculated field in Tableau?

@Ammy999, You can not perform join in ...READ MORE

answered May 17, 2018 in Tableau by Mathew1810
760 views
0 votes
1 answer

How to add parameter and calculated field filter in tableau?

Hi Sindhu,  You cannot add parameter as a ...READ MORE

answered Mar 8, 2019 in Tableau by Cherukuri
• 33,010 points
3,223 views
0 votes
1 answer

How to perform a calculation using one variable with an aggregation in calculated field?

Hi, You can use the calculative field and ...READ MORE

answered May 20, 2019 in Tableau by anonymous
• 33,010 points
206 views
0 votes
0 answers

How to we make a filter(from a calculated field) a context filter in Tableau

Booking Size is a computed field with ...READ MORE

Mar 10 in Tableau by Neha
• 6,260 points
89 views
0 votes
0 answers

How can I sort date field in presence of another date field in Tableau?

Goal: Sort the new ship date in ...READ MORE

Apr 10, 2018 in Tableau by ghost
• 1,790 points
827 views
0 votes
0 answers

How to exclude weekend (Sunday only) to DATEDIFF in Tableau?

My current formula is : DATEDIFF('day', MIN([Date]),MAX([Date])). How do ...READ MORE

Apr 7 in Tableau by Vaani
• 5,040 points
16 views
0 votes
1 answer

Calculated filed with if-then

Below is the required code:  IF (NOT ISNULL([test2])) ...READ MORE

answered Mar 27, 2018 in Tableau by Atul
• 10,230 points
788 views
+1 vote
1 answer

Is it possible to access or install tableau desktop insde tableau server?

Try to understand this, Tableau Server and ...READ MORE

answered Mar 30, 2018 in Tableau by xyz
• 1,560 points

edited Mar 30, 2018 by xyz 309 views
0 votes
1 answer

Hover text shows numbers in decimal points

Do this: 1. Right click on the calculated ...READ MORE

answered Apr 3, 2018 in Tableau by QueenBee
• 1,820 points
272 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP