sqlamazon-redshifttableau-api

End of week day for a date in Tableau


I have date field in this format

dateID
>>20150617

And I want to get

end_of_week_day
>>2015-06-20

So for all the dates in a week, I want to get same end_of_week_day.

Is there any function in Tableau to do this? I am using Amazon Redshift.


Solution

  • First thing is to convert that to a date. Use DATEPARSE to that. Or perhaps just convert the data type of the field and Tableau may understand.

    Now for the actual calculation. You want to get the Saturday of that week. DATEPART, using 'weekday', will return a number, 1 for Sunday till 7 for Saturday. So:

    DATEADD('day',7-DATEPART('weekday',dateID),dateID)
    

    should do the trick