Forum Discussion
Modelling: Best Practices with Multiple Date Columns & Values
Hi Chthonian ,
My tuppence:
1) I think this depends on how you plan to use the dates. If you just want counts/averages where those dates exist or not, then you can handle nulls within your measures, for example:
_incompleteJobs =
CALCULATE(
DISTINCTCOUNT(table[jobnumber]),
ISBLANK(table[completedDate])
)
_completeJobs =
CALCULATE(
DISTINCTCOUNT(table[jobnumber]),
NOT ISBLANK(table[completedDate])
)If you are visualising data over time, then you will need to either replace nulls with today's date, or create a helper column that does this while retaining the original data. In Power Query, I'd add a column like:
completedDateNoBlanks =
if [completedDate] = null then Date.From(DateTime.LocalNow()) else [completedDate]
2) With far-past defaults, such as 01/01/1900, you could again replace these values with something a bit closer to today, but before any true date you are likely to have in your data. This will avoid creating a ridiculously hefty calendar. Regarding calendar table set up, I will always, always, go with M code/Power Query. Why would you want this using system memory at runtime when you can offload the work to the PBI Service refresh?
3) If there is a high chance that you're going to get odd dates popping up in your data, then you can dynamically create your calendar to pick this up at creation time. Here's a few examples of calendar source lines in M that achieve this:
Earliest data date to today
Source = { Number.From(List.Min(table[Date]))..Number.From(DateTime.Date(DateTime.LocalNow())) },
Earliest data date to latest data date
Source = { Number.From(List.Min(table[Date]))..Number.From(List.Max(anotherTable[Date])) },
1st April of earliest data year to today
Source = { Number.From(#date(Date.Year(List.Min(table[Date])),4,1))..Number.From(DateTime.Date(DateTime.LocalNow()))},As before, if these outlier dates are known defaults, then I'd replace them out with something more friendly that doesn't interfere with my 'real' data dates.
Best,
Pete
Thanks for the great reply BA_Pete I appreciate the effort.
It would seem that I am on the right path already then, with regards to points 1 & 2 this is something I am already doing and as I meantioned earlier I just wanted to make sure that I was implementing bad practices.
As for point 3, I will be honest and admit that I had not even considered outlying dates in my m-code so thanks a million for that pointer.
Loving your work!
David