I have a dataset that is updated daily by a query. The query first pulls 11 different dates from the DB based on a combination of month end time frames(each month end that is not a stated time frame) and stated time frames (Current Month End, Prior Month End, Current Quarter End, Prior Quarter end, etc).
The issue I am running into is that in January/April/July/October & February/May/August/November - we are seeing duplicate dates flow into the query. I.E., in the middle of January, the current month-end would be December and the current quarter end would be December. Or in the middle of February, the current 'Prior Month End' and 'Current Quarter End' would both be December.
This is causing aggregation issues downstream in Tableau.
The Date table that is created looks like:
Period Period_Selection
12/31/18 Current Quarter End
12/31/18 Prior Month End
1/31/19 Current Month End
9/30/18 Prior Quarter End
What I would like to do is write a case statement or where clause that limits the data table to a singular instance of each date. These cases will be specific, so it will either affect the pairs: 'current month end' & 'current quarter end' or 'prior month end' and 'current quarter end'. in the above example, the clause would see that there are two examples of '12/31/18' and then drop/ignore one of the instances, for example, drop 'prior month end' and keep 'current quarter end'.
SQL Sample:
SELECT PERIOD_DATE, PERIOD_SELECTION
FROM db.PERIOD_PROMPT
WHERE db_ORDER_NO IN ( '60000000', '50000000', '40000000')-- 50.. = Current Quarter end, 60.. = current month end, 40.. = prior month end
UNION ALL
SELECT ADD_MONTHS(PERIOD_DT, -3) AS PERIOD_DATE
, 'Prior Quarter End' AS PERIOD_SELECTION
FROM db.PERIOD_PROMPT
WHERE db_ORDER_NO IN (50000000) --CURRENT QUARTER END