Forum Discussion
DATEADD With Inconsistent Date Range
Hi All-
I have searched for days on YouTube and the web trying to find solve for the folllowing issue, and hope someone here can help. I have the following dataset that includes sales by store for the last 3 years. When I try to calcuate prior year sales using the DATEADD function, I receive the following error. I believe it is due to the fact that the dataset includes new stores that do not have a prior year to reference. Has anyone found a solution for how to get the DATEADD function to work in this case? I have found a workaround by using the PARALLELPERIOD function when calcualting MTD, QTD, and YTD, however I want to include a custom date filter in my slicer, and need to utilize DATEADD so that it will calculate exactly 365 back from the specified date range.
My fact table: tbl_ReportData
My date table: tbl_Date
I created separate a custom sales measure (in addition to MTD, QTD, and YTD measures I have also created. I have a disconnected table that I am using with the slicer):
Custom Sales =
CALCULATE(
[Total Sales],
FILTER(
tbl_Date,
tbl_Date[Date] >= MIN(tbl_ReportData[Date]) &&
tbl_Date[Date] <= MAX(tbl_ReportData[Date])
)
)
This is the prior year measure along with the error I am receiving:
PY Revenue = CALCULATE([Custom Sales],DATEADD(tbl_ReportData[Date],-365,DAY))
Help! 🙂
4 Replies
- gmsambornSuper User
Hi dhenders1833
Try using your date table in the DATEADD.
PY Revenue = CALCULATE( [Custom Sales], DATEADD( tbl_Date[Date], -365, DAY ) )- dhenders1833Frequent Visitor
Thanks for the recommendation, however that yields the same error as well. It will allow me to pull into the visual alone, however when I pull in store number it then errors out.
Without store #:
With store #:
- gmsambornSuper User
Hi dhenders1833
Can you replicate this problem with a small sample pbix? (I've tried a couple of simple examples and mine seem to work as expected.)
Also, can you double-check the error for your most recent example? The previous error had to do with date tables in particular.