Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Transform a static calendar table imported from Excel into a dynamic one

I have recently imported a data model with all tables and measures from Excel to Power BI, which worked very well.

 

In Excel, in order to generate my date table, I had manually created a regular Excel table with one column that contained all the dates from 2018 to 2026, added it to the data model and then modified it with Excel Power Pivot, adding a large number of dependent calculated columns and measures. It was likewise migrated to Power BI without problems. 

 

In Power BI Desktop, I would now like change this imported static date table into a dynamic date table that is automatically created and updated depending on the the dates that the data model contains.

 

Generally, such a dynamic table can be created by using the "New Table" command followed by the CALENDARAUTO() function in the data pane of Power BI. The problem for me is that my underlying static dates column (between 2018 and 2026) comes from the Power Query Editor and remains static there after the import, because DAX functions like CALENDARAUTO() are not applicable in the Power Query Editor.  Hence, the entire date table with its calulated columns remains static in the data model of Power BI.

 

So how can I exchange the first static column of my dates table through a dynamic one while retaining all of the dependencies of the subsequent calculated columns and measures?

 

1 ACCEPTED SOLUTION

@Anonymous,
Okay here is what you can do:

1. Prepare your fact table with Dates, something like I have in my example:

Migasuke_1-1672080506175.png

2. Retrieve Min and Max (Start and End dates) in numeric format:

obrazek.png
3. Create a table (Calendar), where you have Start Date and End Date in two columns:
obrazek.png
4. Create new column with all dates between those two dates:
obrazek.png5. Clean the table a bit with removing extra tables:
obrazek.png

I can't attach file here, but in case you want - send me PM and I can send you there.




If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

View solution in original post

6 REPLIES 6
AlB
Super User
Super User

Hi @Anonymous 

One option would be to substitute the static table in PQ with the list of dates for a dynamic query that does the same as CALENDARAUTO(), i.e. check the min and max dates in the other tables in your model and generate the list of dates

A second option would be to create a date table from scratch in Power Query and forget about the calculated columns in DAX. There are many example you can download directly from the internet.

 

If  you share the pbix (removing sensitive info), I can have a look to try option 1 

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Anonymous
Not applicable

Thanks for your reply, @AlB .


Basically, my reply to @Migasuke applies to your comment as well.


But in addition, I am much interested in your second option, because that might lead to the solution: creating a dynamic date table in Power Query. How do I do that? Power Query does not accept DAX, only M.

@Anonymous 

1. I do not see how it does. For the first option I am talking about making the changes in Power Query, not in DAX

2. First Google hit:
https://gorilla.bi/power-query/date-table/

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Migasuke
Super User
Super User

Hi @Anonymous ,

I use very simple formula for my Calendar Table. It's a DAX solution but works every time:
Calendar = CALENDAR(MIN('Table'[MyDates]),MAX('Table'[MyDates]))

MyDates is ofcourse a column, which contains dates I want to align with. So depends on my Table and dates, calendar will automaticaly adjust.



If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

Anonymous
Not applicable

Thanks for your reply,  @Migasuke .


My problem is not that I do not know how to create a dynamic date table in general. The expression that you suggest would work, if only I could apply it.

 

My problem is that I cannot apply any DAX expression that creates a table at all, because there is already an entire date table. By some turn I need to replace its static [dates] column by a daynamic one. I have to snatch away the static [dates] column, so to say, and put in a dynamic one insted, while retaining all of the column dependencies that I have throughout my data model.

 

The core of the problem is that my static [dates] column does not come from the Power BI main interface (i.e. the data tab in the left pane), but from the Power Query Editor of Power BI. There it lies in form of a table with one column and is transferred into Power BI. And that is where I currently struggle to replace it by a dynamic one.

@Anonymous,
Okay here is what you can do:

1. Prepare your fact table with Dates, something like I have in my example:

Migasuke_1-1672080506175.png

2. Retrieve Min and Max (Start and End dates) in numeric format:

obrazek.png
3. Create a table (Calendar), where you have Start Date and End Date in two columns:
obrazek.png
4. Create new column with all dates between those two dates:
obrazek.png5. Clean the table a bit with removing extra tables:
obrazek.png

I can't attach file here, but in case you want - send me PM and I can send you there.




If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors