<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged datetable</title>
<link>https://coderlegion.com/tag/datetable</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to Create a Date Table in Power Query</title>
<link>https://coderlegion.com/1884/how-to-create-a-date-table-in-power-query</link>
<description>&lt;p&gt;A Date table is needed for analysis in Power BI because it helps organize and analyze data by date. As the name implies, it enables you to create a calendar (date information) that works for the analysis you want to carry out. i.e weekday, month &amp;amp; year analysis.&lt;/p&gt;
&lt;h3 id=&quot;why-is-date-table-important-in-power-bi-&quot;&gt;Why is Date Table important in Power BI?&lt;/h3&gt;
&lt;p&gt;It can be used for a variety of purposes, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Filtering data: It can filter data by specific date attributes, such as month, quarter, year, or weekday.&lt;/li&gt;
&lt;li&gt;Creating visuals: It helps in creating visuals with dynamic periods, such as the current quarter or month.&lt;/li&gt;
&lt;li&gt;Comparing data: It helps in comparing data over time, such as from&lt;br&gt;
one year to the next or from one month to the next.&lt;/li&gt;
&lt;li&gt;Using DAX time intelligence functions: You can use DAX time&lt;br&gt;
intelligence functions that wouldn’t normally work without a date&lt;br&gt;
table.&lt;/li&gt;
&lt;li&gt;Optimizing data model: When working with large data sets, a separate&lt;br&gt;
date table can help you establish associations between your data&lt;br&gt;
tables and the date table. This can help you boost productivity,&lt;br&gt;
cross-functional reporting, and optimize your data model.&lt;/li&gt;
&lt;li&gt;Standardizing date formatting: It can help create standardized date&lt;br&gt;
formatting. Improving data modeling: It can improve data modeling.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can check out BI Samurai for more explanation on &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.youtube.com/watch?v=vTz2Mxt7npY&quot;&gt;why you need a date table&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A date table can be created in Power Query or DAX. In this article, you will be creating your date table in Power Query.&lt;/p&gt;
&lt;h3 id=&quot;creating-a-date-table-in-power-query&quot;&gt;Creating a Date Table in Power Query&lt;/h3&gt;
&lt;p&gt;Open Power Query, &lt;strong&gt;Home&lt;/strong&gt;&amp;gt;&amp;gt;&lt;strong&gt;&lt;em&gt;Transform Data&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=3221893590656766253&quot; alt=&quot;create a blank query&quot;&gt;&lt;/p&gt;
&lt;p&gt;Click on the New Source dropdown and Create a blank query.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1039528538741641440&quot; alt=&quot;&quot;&gt;&lt;br&gt;
In the formula bar, write an M code to compute the date list.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;= List.Dates(#date(2025,1,1), 365, #duration(1,0,0,0))
List.Dates(start as date, count as number, step as duration)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;List.Dates: the list.date function take 3 arguments (parameters)&lt;/li&gt;
&lt;li&gt;start as date: the date you want to start from&lt;/li&gt;
&lt;li&gt;count as number: the number you want it to count from the start date&lt;/li&gt;
&lt;li&gt;step as duration: the number of days, hours, minutes or seconds you&lt;br&gt;
want to count from the start date.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the code above, the start date is the 1st of January 2025, then count 365 of the duration arguments. The #duration arguments have (1,0,0,0) which translates to 1 day, 0 hour, 0 minute, and 0 second.&lt;/p&gt;
&lt;p&gt;In this case, the date will start from &lt;strong&gt;&lt;em&gt;2025–01–01&lt;/em&gt;&lt;/strong&gt; and &lt;em&gt;count 365 days&lt;/em&gt; from the start date, and that’s what will return in your query.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12635458205200536425&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once a list column has been created, right-click on the column and convert the list to a table (that’s what Power Query allows transformation on).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=9653536742666671699&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Leave delimiter as &lt;strong&gt;None&lt;/strong&gt;. Then click &lt;strong&gt;OK&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NB&lt;/strong&gt;: if you have data that contains a list of items i.e. [dogs, cats, birds] etc. The delimiter in this scenario is the comma separating those items, and if there is a row that doesn’t have a list value, how it will handle it is the second option in the prompt box.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8302681077345617792&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now it’s in table format. (tabular structure)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16445648547649391784&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Change the data type and rename the column, go to &lt;strong&gt;Add Column&lt;/strong&gt;&amp;gt;&amp;gt;&lt;strong&gt;Date&lt;/strong&gt; and start selecting other date parameters to form the calendar table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NB&lt;/strong&gt;: Make sure the Date column is selected before adding a new column.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1257601310870484156&quot; alt=&quot;&quot;&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=10904959118653488391&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can get the scripts to replicate yours&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;let
Source = List.Dates(#date(2025,1,1), 365, #duration(1,0,0,0)),
#&quot;Converted to Table&quot; = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#&quot;Changed Type&quot; = Table.TransformColumnTypes(#&quot;Converted to Table&quot;,{{&quot;Column1&quot;, type date}}),
#&quot;Renamed Columns&quot; = Table.RenameColumns(#&quot;Changed Type&quot;,{{&quot;Column1&quot;, &quot;Date&quot;}}),
#&quot;Inserted Year&quot; = Table.AddColumn(#&quot;Renamed Columns&quot;, &quot;Year&quot;, each Date.Year([Date]), Int64.Type),
#&quot;Inserted Start of Year&quot; = Table.AddColumn(#&quot;Inserted Year&quot;, &quot;Start of Year&quot;, each Date.StartOfYear([Date]), type date),
#&quot;Inserted End of Year&quot; = Table.AddColumn(#&quot;Inserted Start of Year&quot;, &quot;End of Year&quot;, each Date.EndOfYear([Start of Year]), type date),
#&quot;Inserted Month&quot; = Table.AddColumn(#&quot;Inserted End of Year&quot;, &quot;Month&quot;, each Date.Month([Date]), Int64.Type),
#&quot;Inserted Month Name&quot; = Table.AddColumn(#&quot;Inserted Month&quot;, &quot;Month Name&quot;, each Date.MonthName([Date]), type text),
#&quot;Inserted Days in Month&quot; = Table.AddColumn(#&quot;Inserted Month Name&quot;, &quot;Days in Month&quot;, each Date.DaysInMonth([Date]), Int64.Type),
#&quot;Inserted Start of Month&quot; = Table.AddColumn(#&quot;Inserted Days in Month&quot;, &quot;Start of Month&quot;, each Date.StartOfMonth([Date]), type date),
#&quot;Inserted End of Month&quot; = Table.AddColumn(#&quot;Inserted Start of Month&quot;, &quot;End of Month&quot;, each Date.EndOfMonth([Date]), type date),
#&quot;Inserted Quarter&quot; = Table.AddColumn(#&quot;Inserted End of Month&quot;, &quot;Quarter&quot;, each Date.QuarterOfYear([Date]), Int64.Type),
#&quot;Inserted Start of Quarter&quot; = Table.AddColumn(#&quot;Inserted Quarter&quot;, &quot;Start of Quarter&quot;, each Date.StartOfQuarter([Date]), type date),
#&quot;Inserted End of Quarter&quot; = Table.AddColumn(#&quot;Inserted Start of Quarter&quot;, &quot;End of Quarter&quot;, each Date.EndOfQuarter([Date]), type date),
AddColumns = Table.AddColumn(#&quot;Inserted End of Quarter&quot;, &quot;Month Name Short&quot;, each Date.ToText([Date], &quot;MMM&quot;), type text),
AddMonthAndDay = Table.AddColumn(AddColumns, &quot;Month &amp;amp; Day&quot;, each Date.ToText([Date], &quot;MMM&quot;) &amp;amp; &quot; &quot; &amp;amp; Text.From(Date.Day([Date])), type text),
AddMonthAndYear = Table.AddColumn(AddMonthAndDay, &quot;Month &amp;amp; Year&quot;, each Date.ToText([Date], &quot;MMM&quot;) &amp;amp; &quot;-&quot; &amp;amp; Date.ToText([Date], &quot;yyyy&quot;), type text),
AddYearMonthNum = Table.AddColumn(AddMonthAndYear, &quot;Year Month Num&quot;, each Number.FromText(Date.ToText([Date], &quot;yyyyMM&quot;)), Int64.Type),
AddYearMonthName = Table.AddColumn(AddYearMonthNum, &quot;Year Month Name&quot;, each Date.ToText([Date], &quot;yyyy-MMM&quot;), type text),
#&quot;Inserted Day&quot; = Table.AddColumn(AddYearMonthName, &quot;Day&quot;, each Date.Day([Date]), Int64.Type),
#&quot;Inserted Day of Week&quot; = Table.AddColumn(#&quot;Inserted Day&quot;, &quot;Day of Week&quot;, each Date.DayOfWeek([Date]), Int64.Type),
#&quot;Inserted Day of Year&quot; = Table.AddColumn(#&quot;Inserted Day of Week&quot;, &quot;Day of Year&quot;, each Date.DayOfYear([Date]), Int64.Type),
#&quot;Inserted Start of Day&quot; = Table.AddColumn(#&quot;Inserted Day of Year&quot;, &quot;Start of Day&quot;, each Date.StartOfDay([Date]), type date),
#&quot;Inserted End of Day&quot; = Table.AddColumn(#&quot;Inserted Start of Day&quot;, &quot;End of Day&quot;, each Date.EndOfDay([Date]), type date),
#&quot;Inserted Day Name&quot; = Table.AddColumn(#&quot;Inserted End of Day&quot;, &quot;Day Name&quot;, each Date.DayOfWeekName([Date]), type text)
in
#&quot;Inserted Day Name&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Happy Querying!!! Now you have a date table to use for your analysis.&lt;/p&gt;
&lt;p&gt;If you encounter any difficulties or have any questions, feel free to reach out through the comment box. You can connect with me on &lt;a rel=&quot;nofollow&quot; href=&quot;https://x.com/mubardauda&quot;&gt;Twitter&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://linkedin.com/in/mubardauda&quot;&gt;LinkedIn&lt;/a&gt; where I share my daily activities about data analytics, personal experience, and career life.&lt;/p&gt;
</description>
<category>Power Query</category>
<guid isPermaLink="true">https://coderlegion.com/1884/how-to-create-a-date-table-in-power-query</guid>
<pubDate>Fri, 18 Apr 2025 10:43:44 +0000</pubDate>
</item>
</channel>
</rss>