Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m going to show you how to keep your practice dataset updated every time you do a refresh. You may watch the full video of this tutorial at the bottom of this blog.

If you really want to improve your DAX skills, the way way is to use it and put it into practice. And to do that, you’d need a practice dataset that helps you visualize and work on possible real-life scenarios.

The problem with practice datasets is that the data is usually static. For you to practice efficiently, you need to give the impression that the data is live.

Table of Contents

Setting Up A File Path For The Practice Dataset

For my sample data, I have an Excel file containing Sales data from 2014, 2015 and 2016.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

This is the data that I need to update.

The document location can be found here on my Quick Access Toolbar.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I need that to set up a parameter for my file path. So I’m going to copy that document location.

There’s an access point to the Quick Access Toolbar on the right side of that.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Once I press that, I get this screen.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So I’ll go for All Commands and then choose Document Location. Add that to the Quick Access Toolbar and press OK.

Now, I’ll go into the Power Query to create the parameter that will hold my file path. This step is important because it allows all the queries inside the model to be restored should another user change the file location.

So I’ll create a new parameter.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m going to call that FileLocation.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Under type, I’m going to select Text. And for Current Value, I’ll paste in the document location I copied earlier.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m going to create a new query.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’ll choose the sample data I’ll be using as my practice dataset.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

A number of different tables will come up here since I have Sales data from 2014, 2015 and 2016. I just need to choose the first one, which is Sales_2014.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now that I’ve chosen the Sales_2014 data, it’s time to change that hard-coded file location into a dynamic file location.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll go into the Advanced Editor and select everything that’s related to the file location.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then, I’ll change that into the FileLocation parameter I created earlier.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’ll press Done to lock those changes into the Sales_2014 query.

Creating The Data Prep Folder

Looking at the Applied Steps for the Sales_2014 query, I’ll click on the Navigation step. This shows me that it references the Source step.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

It also references Sales_2014 which is shown as a Table. It also shows that it’s extracting data from the Data column.

Now, let me look at the Source step next.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

The Source step shows me everything that resides in my Excel file. If I check those coordinates, I see Sales_2014, and under Kind, it says Table.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

When I look up the data column, it shows the Table object that was extracted.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So I can duplicate this query to come up with the 2015 data. To do that, I just need to right click on Sales_2014 then choose Duplicate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then, I”ll step back into the Navigation step.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll change that year from 2014 to 2015.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll also also rename that here under Properties. I’ll call it Sales_2015.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

This time, I’ll duplicate Sales_2015.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’ll step back into the Navigation step and change the year to 2016.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I now have my complete Sales data. But these queries should not be loaded into my model. I just need to right click on each one of them and deselect Enable load.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, I’m going to select all the queries and place them in a single folder to make things more organized.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll call this folder Data Prep.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Getting The Day Offset

The sample data here under Data Prep is going to be static. This means that the 1st and the last dates will never change.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So I’ll go into Sales_2016 and I’m going to sort the Order Date column in descending order to get the last date from this data set.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

The last date in this data set is December 31st 2016.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, I’ll create a new query.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then, I’ll check what the Day Offset is from the last date in the data set to today. This means I need to find out what today is. To do that, I’ll use the function DateTime.FixedLocalNow. This will give me the date and time from the machine that I’m working on.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

But I don’t really need the time portion here. I only need the date portion of this value.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So, I’m going to extract the date using Date.From.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then from that value, I’m going to subtract the last date in my data set. Since the data is static, I can use the intrinsic date value. So that’s #date and then reference December 31st, 2016.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, I need to extract the number from this difference. So I’ll add Number.From and close it off with a parenthesis. Then, press enter.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll rename this as DayOffset.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Setting Up Dynamic Date Ranges

I also need dynamic date ranges for my date table. I’ll start off by doing a right click on the Data Prep folder and creating a new Blank Query.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then, I’ll work on the Start Date of my Date table.

I always want the 1st day of the year as my Start Date. So I’ll put the equal sign and use the function Date.StartOfYear.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Since I need to give that a value, I’m going to offset that by using Date.AddDays.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’ll use the intrinsic date value again and use the 1st date on my data set, which is June 1, 2014.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I also need the number of days that I calculated in my DayOffset, so I’m going to add that.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Once I press enter, it gives me January 1, 2017. This is going to be the 1st date in my date table.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll rename that to fxStartDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, I can set up my End Date. I’m going to copy this syntax I used on my Start Date.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll create a new blank query.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then rename it to fxEndDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’m going to paste the syntax from my Start Date.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Instead of StartOfYear, I’ll change this to EndOfYear.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m also going to use the last date of my data set, which is the 31st of December.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

When I press enter, it returns December 31st, 2020.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Creating A Single Sales Table

I’m going to combine the 3 tables into a single Sales table. To do that, I’m going to create a new query.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll call this my Sales table.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then I’ll combine Sales_2014, Sales_2015 and Sales_2016 into a single table.

I know that you can do that through the ribbon, but there’s also an option to do it directly in the formula bar. I’ll choose that 2nd option.

I’ll start with Table.Combine.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Table.Combine requires a list of tables. So I’ll add a list initializer, which is those curly brackets, then I’m going to name the 3 queries. Press enter after that.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Transforming The Order Date Column

Now that I have most of the elements I need, I’m going to generate a key part of the syntax that I’m going to use later on to complete my dynamic practice dataset.

I’ll start by selecting two number columns. I can use the Delivery Region Index and the Product Description Index. On your end, you can press down either Shift or Ctrl to select both columns.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Under the Transform tab, I’ll select Absolute Value.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

If I look at the formula bar, it will show the Table.TransformColumns function. This is the key to the final solution.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

The function takes a list of transformation lists. As you can see, there are 2 lists here nested inside each other.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

It references the column name as text. That’s why Delivery Region Index was referenced here on the 1st set.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then it adds a transformation step.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

It does the same in a separate list for the Product Description Index column.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, I’ll head to the Advanced Editor.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I don’t want absolute values. So the first thing I’m going to do is offset my date. I’ll create a function called fxUpdateDate to do that. It’s going to use the current date, which I’ll type in as cDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Then, I’m going to use the Date.AddDays function again, which also uses the cDate. I’ll also use the DayOffset I created earlier.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

All that the fxUpdateDate does is take the date. So if I pass that onto the Table.TransformColumns function, it’s going to start checking for each recorded date.

So, if I’m working on the 1st row here, for example, it’s going to consider June 1, 2014, as the cDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

And every time the function gets called, it’s going to add that DayOffset that I created.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now, the Table.Transform step shows up in Calculated Absolute Value.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m going to rename that first and call it the UpdateOrderDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

This UpdateOrderDate step involves my Table.TransformColumns which equals the Source.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

The initial table listed is the Delivery Region Index. But there’s no need to transform that. So I’m going to change that 1st column referenced into the OrderDate column.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

It also says here that the transformation is going to be in absolute values.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Since I don’t want that, I’m going to change that into fxUpdateDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

The type is not going to be an absolute value either, so I also need to change this part.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll change that into a date.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I only need one transformation, so I’ll delete the 2nd list along with the transformation step that comes with that set…

Create A Perpetually Updated Practice Dataset In LuckyTemplates

…so it’s just one transformation for the OrderDate column.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Because I renamed the step for Calculated Absolute Value, I need to change that in my in statement as well.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Now it shows UpdateOrderDate as well.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So the OrderDate column will now call this function for each record in Table.TransformColumns.

Looking into the Order Date column, I can see that this has been updated.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

And if I sort that in descending order, it shows July 7, 2020 as the current date.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

So I’m going to remove that Sort step because I don’t really need that. I only did that to check if the current date had also been updated.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Applying Time Intelligence Using M Code

My model is all about Sales data. Since I’m going to do some time intelligence, I would need a Date table.

So I’ll go to the . In the M-code Showcase, I’m going into the Extended Date Table topic.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Scroll up to the very top of the page and copy the entire code.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Going back into my model, I’m going to create a new blank query and paste that M code in. Press Done.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll rename that query into fxCalendar.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

For my parameters, I’ll use the 1st of January for the StartDate and the 31st of January for the EndDate. Then press Invoke.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Once the table comes up, I’m going to rename it as Dates.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Remember that I already created the start and end dates by looking at the 1st date on the sample dataset and offsetting that by my DayOffset. So the fxStartDate here shows up as January 1st, 2017.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

As for the fxEndDate, it returns the 31st of December, 2020.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I can go back to the Dates table and update that Source step there as well.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

It lists the parameters in the order that they were called. The first parameter should show the start date.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m going to change that into fxStartDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’m also going to replace the second parameter.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll put in the fxEndDate.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

Once I press Enter, the transformation is complete. I now have a fully up-to-date practice dataset that will always remain current.

Create A Perpetually Updated Practice Dataset In LuckyTemplates

I’ll just click on Close & Apply to lock all of those steps in.

Create A Perpetually Updated Practice Dataset In LuckyTemplates


Creating a Dynamic Date Query Table in LuckyTemplates: A Query Editor Tutorial
Setting Up A Dynamic StartDate And EndDate For Power Query Date Tables
Using The Offset Function In Extended Date Tables

Conclusion

As I mentioned earlier, having your own dynamic practice dataset will definitely level up your game when it comes to LuckyTemplates. It allows you to practice your skills and knowledge while pretending that you’re working on a real-life scenario.

If you want to learn more about making your start and end dates dynamic especially for a practice dataset you’re using, you can check out the LuckyTemplates Forum. There are a lot of conversations there about this as well as other relevant topics. You may even find other approaches that would work for you.

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.