Forum Discussion
MTD Previous
Two things.
First, from a DAX perspective, I believe the formula you want is DATEADD. DateAdd will return partial periods whereas other functions return whole periods. Check this blog post for a good explanation: DateAdd
Second, a best practice I always use is to have a "trimmed" dates table, meaning I don't have dates that go beyond where I have data in my fact table. For example, I do a lot of month end reporting, so I always trim my dates table to stop at the last day of the prior month. The great thing about Power Query/M Language is that you can code this to basically be automatic.
So for your example, you would start by hardcoding that you want the date to be less than or equal to today's date. Once you do this, it will add a step to the query and you will see the M formula in the formula bar showing you what it's doing. Then, you can erase the hardcoded date in that formula bar and replace it with:
<=Date.From(DateTime.LocalNow())
This way, every time you refresh the data, your calendar table will always stop at todays date. There's a ton of date functions in M, so check out the Formula reference if there's other manipulations you need to make.
I have already trimmed my calendar dimension in my tabular to not include any future dates. My fact is not going to have future sales so I probably don't have to worry about that. Doing this has not fixed my problem.