Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll show you how to set up dynamic start dates and end dates using LuckyTemplates’s power query date tables.

If you’ve been following this series on different Time Intelligence subjects, you already know how to create a date table using power query functions. You might have also read about how to change the end date for that table. You may watch the full video of this tutorial at the bottom of this blog.

This time, however, I’ll show you a few alternatives.

Table of Contents

The Power Query Date Table

I’m going to start off by heading to the power query date table function. It shows four date parameters – a required StartDate, a required EndDate, an optional FYStartMonth and an optional holiday list.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Note that for every query you invoke, the corresponding query function will show up here.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

You’ll also see the date parameters in the same order they were listed earlier. So this shows the StartDate, the EndDate and the fiscal year. It also shows null for the holiday list.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Now that you’ve seen the parts of the date table function, I’ll show you the different query functions you can use.

Power Query Date Table Functions

If I go into my Sales table, which is also my fact table, it shows an OrderDate column.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

If I click on the dropdown beside OrderDate, it will show that the first date in this calendar is the 24th of September 2017.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

So I’m going to extract that data by creating a new blank query.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll use the List.Min function.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Looking at the description, it shows that List.Min returns the minimum item in the list.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

For this function, I’m going to reference the Sales table and the OrderDate column.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Once I hit enter, it gives me the first date, which is the 24th of September, 2017.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll rename this query and call it FirstSale.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

But making the calendar start on the 24th of September probably doesn’t make sense. So I’ll turn this back into the start of the year.

To do that, I’ll use a blank query again. This time, I’ll use the function Date.StartOfYear.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Date.StartOfYear returns the first value of a given year for a date, datetime or datetimezone value.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

For my date value, I’m going to use FirstSale.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Once I hit enter, it now shows the first of January, 2017.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll rename this query too, and call it StartOfYear.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

But there’s another way to get exactly the same value. That’s by using the intrinsic date.

So I’m going to create a new query again and use #date, which is the intrinsic date value.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

For #date, I need a dynamic value. So I’ll use Date.Year and reference FirstSale. I would also use the 1st of January, which is represented by the two 1’s on the measure.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll name this fxStartDate.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Now, I’m going to go back to the date table query. Now, I can change the StartDate parameter.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

It doesn’t really matter if I select StartOfYear or fxStartDate since they’ll yield the same result.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’m just going to use the fxStartDate so I can put a proper value here.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Now, my calendar starts from January 1st, 2017.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Of course, I can do the exact same thing for the EndDate. I just need a blank query again, but this time, I’ll be using the function List.Max. I’m also going to reference Sales and the OrderDate column.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

This now shows the last date from the Sales table, which is the 24th of April, 2020.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll double check if that’s correct by sorting this column in a descending manner. Surely enough, the column does show April 24 2020 as the final date.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll rename this query LastSale.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Again, I can do exactly the same thing for the end of the year just as I did for the StartOfYear.

On a new query, I’ll use Date.EndOfYear and reference LastSale.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll call this EndOfYear.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Remember how I used the intrinsic date for the StartOfYear? I can also do that to return the 31st of December of any given year. However, you also have to think about the possibility of the data spilling over into the new year once it reaches that end date.

This is how you can deal with that.

I’ll use Date.AddYears and reference EndOfYear.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

For the number of years, I’m just going to add 1.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Sure enough, the date now shows 2021.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll call this EndOfNextYear.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’m now going to replace the EndDate on my date table.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

I’ll use EndOfNextYear to replace that.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Double checking my years, it now runs to 2021.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

To save and apply all of the changes I made, I’m going to click on Close & Apply.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Other Date Functions

Go to docs.microsoft.com and look up Power Query M formula language.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

Once that shows up, look for the Date functions overview.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables

This will show you all the other date functions that you can use when working inside power query date tables.

Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables


Build A Comprehensive Date Table In LuckyTemplates Really Fast
Time Comparison For Non Standard Date Tables In LuckyTemplates
Adding Workday And Weekend Numbers Into Your Date Table: Time Intelligence Technique In LuckyTemplates

Conclusion

There are many functions you can play with when using power query date tables, which is why I suggest looking through each one of them.

Start creating blank queries and using them to see what happens. This is the best way to find out how each query function can help you out in the scenarios you might face in the future.

Honestly, the power query is an amazing tool that could give you great insights, especially when dates are involved. Try to check out other posts about time intelligence in this blog to see what other techniques you can apply.

All the best,

Melissa

Leave a Comment

Excel Hücrelerini Metne Sığdırma: 4 Kolay Çözüm

Excel Hücrelerini Metne Sığdırma: 4 Kolay Çözüm

Excel hücrelerini metne sığdırmak için güncel bilgileri ve 4 kolay çözümü keşfedin.

Bir Excel Dosyasının Boyutu Nasıl Küçültülür – 6 Etkili Yöntem

Bir Excel Dosyasının Boyutu Nasıl Küçültülür – 6 Etkili Yöntem

Bir Excel Dosyasının Boyutunu Küçültmek için 6 Etkili Yöntem. Hızlı ve kolay yöntemler ile verilerinizi kaybetmeden yer açın.

Pythonda Self Nedir: Gerçek Dünyadan Örnekler

Pythonda Self Nedir: Gerçek Dünyadan Örnekler

Python'da Self Nedir: Gerçek Dünyadan Örnekler

Rde Bir RDS Dosyası Nasıl Kaydedilir ve Yüklenir

Rde Bir RDS Dosyası Nasıl Kaydedilir ve Yüklenir

R'de bir .rds dosyasındaki nesneleri nasıl kaydedeceğinizi ve yükleyeceğinizi öğreneceksiniz. Bu blog aynı zamanda R'den LuckyTemplates'a nesnelerin nasıl içe aktarılacağını da ele alacaktır.

İlk N İş Günü Tekrar Ziyaret Edildi – Bir DAX Kodlama Dili Çözümü

İlk N İş Günü Tekrar Ziyaret Edildi – Bir DAX Kodlama Dili Çözümü

Bu DAX kodlama dili eğitiminde, GENERATE işlevinin nasıl kullanılacağını ve bir ölçü başlığının dinamik olarak nasıl değiştirileceğini öğrenin.

LuckyTemplatesda Çok İş Parçacıklı Dinamik Görsel Tekniği Kullanarak Öngörüleri Sergileyin

LuckyTemplatesda Çok İş Parçacıklı Dinamik Görsel Tekniği Kullanarak Öngörüleri Sergileyin

Bu eğitici, raporlarınızdaki dinamik veri görselleştirmelerinden içgörüler oluşturmak için Çok Kanallı Dinamik Görseller tekniğinin nasıl kullanılacağını kapsayacaktır.

LuckyTemplatesda İçeriği Filtrelemeye Giriş

LuckyTemplatesda İçeriği Filtrelemeye Giriş

Bu yazıda, filtre bağlamından geçeceğim. Filtre bağlamı, herhangi bir LuckyTemplates kullanıcısının başlangıçta öğrenmesi gereken en önemli konulardan biridir.

LuckyTemplates Çevrimiçi Hizmetindeki Uygulamaları Kullanmak İçin En İyi İpuçları

LuckyTemplates Çevrimiçi Hizmetindeki Uygulamaları Kullanmak İçin En İyi İpuçları

LuckyTemplates Apps çevrimiçi hizmetinin çeşitli kaynaklardan oluşturulan farklı raporların ve içgörülerin yönetilmesine nasıl yardımcı olabileceğini göstermek istiyorum.

Fazla Mesai Kâr Marjı Değişikliklerini Analiz Edin - LuckyTemplates ve DAX ile Analitik

Fazla Mesai Kâr Marjı Değişikliklerini Analiz Edin - LuckyTemplates ve DAX ile Analitik

LuckyTemplates'da ölçü dallandırma ve DAX formüllerini birleştirme gibi teknikleri kullanarak kâr marjı değişikliklerinizi nasıl hesaplayacağınızı öğrenin.

DAX Studioda Veri Önbellekleri İçin Materyalleştirme Fikirleri

DAX Studioda Veri Önbellekleri İçin Materyalleştirme Fikirleri

Bu öğreticide, veri önbelleklerini gerçekleştirme fikirleri ve bunların DAX'ın sonuç sağlama performansını nasıl etkilediği tartışılacaktır.