Maxmilián Ottomanský
01

Maxmilián Ottomanský

JMÉNO

Maxmilián Ottomanský

ROLE

Junior Sales Engineer

TELEFON

+420 797 709 136

EMAIL
01

Power BI Powerful Datekey table!

Have you ever struggled to create the perfect Date table in Power BI or Excel? Messy calendars, complex relationships, and time-consuming formulas can make it a frustrating experience. I’ve developed an advanced Power Query solution to streamline date management – and I’m eager to share it with the community!

Why You Need This Query

  • Effortless Date Modeling: My query generates a comprehensive Date table, complete with columns for year, month, quarter, week, fiscal periods, and more.
  • Enhanced Time Intelligence: Analyze your data seamlessly across different time periods with pre-calculated aggregations.
  • Customization: Adapt the query to fit your company’s specific calendar requirements.
  • Plug-and-Play Simplicity: Forget complex DAX formulas; connect this date table to your data model, and you’re ready for advanced analysis!

How to Implement – A Quick Guide

  1. Copy the Query: I’ll provide the full M code for easy copy-pasting.
  2. Open Power Query: In Excel or Power BI, select “Get Data” -> “Blank Query.”
  3. Advanced Editor: Open the Advanced Editor and paste the query.
  4. Adjust Parameters (Optional): Modify the start date, end date, or any custom columns to your needs.
  5. Load and Enjoy!: Load the query as a new table, connect it to your data model, and start analyzing with ease!

The Transformative Impact of a Robust Date Table

With this query in your toolkit, you’ll experience:

  • Faster analysis: Pre-calculated time columns speed up calculations and visualizations.
  • Deeper insights: Easily compare data across weeks, months, years, and custom periods.
  • Reduced errors: A standardized Date table minimizes manual mistakes.

Ready to take your data analysis to the next level? Feel free to copy the code!

let Source = List.Dates(StartDate, Length, #duration(1, 0, 0, 0)), StartDate = #date(2022, 1, 1), TodayDate = DateTime.Date(DateTime.LocalNow()), Length = Duration.Days(TodayDate - StartDate)+1, #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}), #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Inserted Day" = Table.AddColumn(#"Added Index", "Day Number", each Date.Day([Date]), Int64.Type), #"Inserted Week of Year" = Table.AddColumn(#"Inserted Day", "Week Number", each Date.WeekOfYear([Date]), Int64.Type), #"Inserted Month" = Table.AddColumn(#"Inserted Week of Year", "Month Number", each Date.Month([Date]), Int64.Type), #"Inserted Quarter" = Table.AddColumn(#"Inserted Month", "Quarter", each Date.QuarterOfYear([Date]), Int64.Type), #"Added Prefix" = Table.TransformColumns(#"Inserted Quarter", {{"Quarter", each "Q" & Text.From(_, "en-AU"), type text}}), #"Inserted Year" = Table.AddColumn(#"Added Prefix", "Year", each Date.Year([Date]), Int64.Type), #"Inserted Day Name" = Table.AddColumn(#"Inserted Year", "Day Name", each Date.DayOfWeekName([Date]), type text), #"Extracted First Characters" = Table.TransformColumns(#"Inserted Day Name", {{"Day Name", each Text.Start(_, 3), type text}}), #"Inserted Month Name" = Table.AddColumn(#"Extracted First Characters", "Month Name", each Date.MonthName([Date]), type text), #"Extracted First Characters1" = Table.TransformColumns(#"Inserted Month Name", {{"Month Name", each Text.Start(_, 3), type text}}), #"Inserted Days in Month" = Table.AddColumn(#"Extracted First Characters1", "Days in Month", each Date.DaysInMonth([Date]), Int64.Type), #"Inserted Day of Week" = Table.AddColumn(#"Inserted Days in Month", "Day of Week", each Date.DayOfWeek([Date])+1), #"Inserted Year1" = Table.AddColumn(#"Inserted Day of Week", "Financial Year", each Date.Year([Date]+#duration(184,0,0,0)), Int64.Type), #"Added Conditional Column" = Table.AddColumn(#"Inserted Year1", "Financial Month", each if ([Month Number]-6) <= 0 then [Month Number]+6 else [Month Number]-6), #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Financial Week", each if [Month Number] > 6 then [Week Number]-26 else [Week Number]+26), #"Duplicated Column" = Table.DuplicateColumn(#"Added Conditional Column1", "Month Name", "Financial Month Name"), #"Inserted Quarter1" = Table.AddColumn(#"Duplicated Column", "Quarter1", each Date.QuarterOfYear([Date]), Int64.Type), #"Added Conditional Column2" = Table.AddColumn(#"Inserted Quarter1", "Financial Quarter", each if [Quarter1] > 2 then [Quarter1] -2 else [Quarter1] +2), #"Added Prefix1" = Table.TransformColumns(#"Added Conditional Column2", {{"Financial Quarter", each "Q" & Text.From(_, "en-AU"), type text}}), #"Removed Columns" = Table.RemoveColumns(#"Added Prefix1",{"Quarter1"}), #"Added Custom" = Table.AddColumn(#"Removed Columns", "Year and Month", each (100*[Year])+[Month Number]), #"Změněný typ" = Table.TransformColumnTypes(#"Added Custom",{{"Year and Month", Int64.Type}}), #"Přidané: Vlastní" = Table.AddColumn(#"Změněný typ", "Year-month", each Text.From(Date.Year([Date])) & "-" & Text.PadStart(Text.From(Date.Month([Date])), 2, "0")) in #"Přidané: Vlastní"

cs_CZCzech