When we talk about data analysis in Power BI, creating a Date table is inevitable. There are different methods to create a Date table either in DAX or in Power Query. In DAX you my use either
CALENDAR() function or
CALENDARAUTO() function to create the Date table. In Power Query you may use a combination of
#duration() functions. Either way, there is one point that is always challenging and it is how to find out a proper date range, starting from a date in the past and ending with a date in the future, that covers all relevant dates within the data model. One simple answer is, we can ask the business. The SMEs know what the valid date range is..
While this is a correct argument it is not always the case. Especially with the Start Date which is a date in the past. In many cases the business says:
Lets’s have a look at the data to find out.
That is also a correct point, we can always a look at the data, find all columns with either
DateTime datatypes then sort the data in ascending or descending order to get the results. But what if there many of them? Then this process can be very time consuming.
Many of you may already thought that we can use
CALENDARAUTO() in DAX and we are good to go. Well, that’s not quite right. In many cases there are some
DateTime columns that must not be considered in our Date dimension. Like Birth Date or Deceased Date. More on this later in this post.
In this post I share a piece of code I wrote for myself. I was in a situation to identify the Start Date and the End Date of the date dimension many times, so I thought it might help you as well.
How it works?
The Power Query expressions I share in this post starts with getting all existing queries using:
- Filtering out the current query name, which is GetMinMaxAllDates in my sample, to avoid getting the following error:
Continue reading “Finding Minimum Date and Maximum Date Across All Tables in Power Query in Power BI and Excel”
Expression.Error: A cyclic reference was encountered during evaluation.