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, 2022 in Tableau by Vaani
• 7,060 points
542 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 the ...READ MORE

answered May 17, 2018 in Tableau by Mathew1810
1,245 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,030 points
4,785 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,030 points
536 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, 2022 in Tableau by Neha
• 9,060 points
651 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
1,210 views
0 votes
1 answer

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

To exclude Sundays from the DATEDIFF calculation ...READ MORE

answered Jul 3, 2023 in Tableau by anonymous
• 1,380 points
699 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,240 points
1,357 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 673 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
716 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP