6 Replies Latest reply on Jun 24, 2019 8:19 AM by Paul Wachtler

# Tableau Calculated field question

Hi, I need help with tableau calculated field. The calculated field should be in the following way. I have a field called status date. What my calculated field should do is say, if todays date is greater than 15th of the month, then status date should be eqla to 16 th 30th (or 31st), till the end of the month.........say if todays date is <= 15th of the given month, then status date should be equal to 1st to 15th of that month. how would I define this calculated field.

• ###### 1. Re: Tableau Calculated field question

Hi, Sashank

Do you have a sample workbook to share?

ZZ

• ###### 2. Re: Tableau Calculated field question

Hi Sashank,

Are you able to share your workbook for this?  I'm not completely following your question.

So if today's date is greater than the 15th of the month, you want the calculated field to return a string that says "16th - 30th"?  Or do you want the calculated field to return TRUE if it's between the 16th and 30th?

Best,

Paul

• ###### 4. Re: Tableau Calculated field question

i can't share the workbook because of some restrictions. The req is, need to have boolean filter, status date = June 1st to June 15th, it should pull  the date between june 1st and june 15th, since todays date is june 24th. When July 1st comes, it should pull the data from june 16th to june 30th////

• ###### 5. Re: Tableau Calculated field question

DATE(IF DAY([Date]) < 15 THEN DATETRUNC('month',[Date] )

END)

Here you go I tried it in mine and if you want to include the 15th in the 1st of the month part do <= instead of <

• ###### 6. Re: Tableau Calculated field question

Thanks Sashank, I think I understand.

So you want it to include status dates of the 16th through the end of the month if todays date is greater than the 15th.  If today's date is less than or equal to the 15th, only include Status Dates of the 1st through the 15th.  You can do that like this:

if datepart('day',today()) > 15

then if datepart('day', [status date]) > 15 then "Include" else "Exclude" end

elseif datepart('day',today()) <= 15

then if datepart('day', [status date]) <= 15 then "Include" else "Exclude" end

end

Drag that field onto your filter shelf and select "Include".  Let me know if that works for you.

Best,

Paul