LuckyTemplates Tip: How To Compare First N Business Days

LuckyTemplates Tip: How To Compare First N Business Days

For this post, I would like to talk about a recent LuckyTemplates tip that I came up with for a member of the . The question dealt with a useful pattern in terms of looking at the first N business days or first N billable days of a given month versus the same period in the previous month. You can watch the full video of this tutorial at the bottom of this blog.

TJ Henneman wanted to compare the first 5 billable days of the current month with the first 5 billable days of the previous month, and then on Day 10, Day 15, and Day 20. Note that he wants to look only at the billable days, so this does not include weekends and holidays. You can check out his post .

LuckyTemplates Tip: How To Compare First N Business Days

I think that there’s a really interesting power query solution to be had here. I also worked with an interesting DAX solution on this problem. I will go over the latter in another tutorial.

I also want to walk you through a recent reporting technique I used for LuckyTemplates Challenge #16. I used a scrolling KPI indicator that will work really well for this particular problem.

But for this LuckyTemplates tip, I’ll touch on the power query solution. Let’s jump into LuckyTemplates and take a look at our data. For this one, I simulated the data using the practice dataset tool that we put together at LuckyTemplates, which you can use for free. This is great for putting together a basic star schema dataset and for testing out solutions.

Table of Contents

Our Data Model

Our data model uses our Extended date table plus a series of dimension tables. We also have a Sales table with three years of partial data in the first year, full data in the second year, and partial data in the third year. Lastly, we also have a Measures table.

LuckyTemplates Tip: How To Compare First N Business Days

I also slightly modified this dataset. I brought in a Holiday table and linked it to the Extended date table so that it can properly calculate the holidays we will remove in this analysis. If you’re not sure how to do this, check out this tutorial.

Then I filtered out the first partial month in the dataset because that month only had a few days of data and didn’t have the business days that we need. Take note that we’re starting with the first full month; but other than that, this will be your standard dataset. So let’s jump into power query and start working on this LuckyTemplates tip.

If we take a look at our data, you can see we have different orders on a particular day. The goal is to number everything that starts with April 1st as our first business day, April 2nd as our second business day, April 3rd as our third business day, and so on. We’ll number this from 1 to N business days for each month while taking out the weekends and holidays.

LuckyTemplates Tip: How To Compare First N Business Days

Creating A Duplicate Table

To start things off, we need to create a duplicate of this table so we can aggregate into Total Sales and bring it into the individual observation level. We’re going to call this duplicate table Sales Aggregated.

LuckyTemplates Tip: How To Compare First N Business Days

You may have noticed, we duplicated the Sales table rather than just referencing it. In this case, we’re going to join this table with the original Sales table. If we reference it, it will cause problems when we join the two.

The first thing to do is use a Group By on the OrderDate column. Click on the Advanced button because it will give us a full picture of what we’re doing here. We will put Total Day Sales as our new column name, and it will be the sum of our line total.

LuckyTemplates Tip: How To Compare First N Business Days

Now we have each date (first column) and total sales for that day (second column).

LuckyTemplates Tip: How To Compare First N Business Days

Merging The Dates Table

The next step in this LuckyTemplates tip is to merge this with our Dates table to figure out which of those days are business days and which of them are not. We can Group By again, split those out, and number them appropriately.

We will merge our Dates table and link the OrderDate to Date. We can see at the bottom part that the selection matches every row of the table, as it should.

LuckyTemplates Tip: How To Compare First N Business Days

The field we’re primarily interested in is IsBusinessDay.

LuckyTemplates Tip: How To Compare First N Business Days

This is the primary field that we’ll be grouping on, and then use the Month & Year and MonthnYear fields.

LuckyTemplates Tip: How To Compare First N Business Days

We also need to check on DayofWeekName to make sure that we’re filtering out the proper days.

LuckyTemplates Tip: How To Compare First N Business Days

Once we click on the OK button, it will give us exactly what we need.

LuckyTemplates Tip: How To Compare First N Business Days

We also have to make sure that our Order Date is sorted in ascending order.

LuckyTemplates Tip: How To Compare First N Business Days

Then we go back and create a second Group By.

LuckyTemplates Tip: How To Compare First N Business Days

This time, we’ll click on the Advanced button, group on Month & Year, and then add a second grouping.

LuckyTemplates Tip: How To Compare First N Business Days

The second grouping is for IsBusinessDay so we can number the ones where business days are true.

LuckyTemplates Tip: How To Compare First N Business Days

Then we’ll create an AllRows function so it will not aggregate and we’ll be able to go back to the original level of granularity.

LuckyTemplates Tip: How To Compare First N Business Days

This should give us nested tables where we can see a table for true and a table for false for each month.

LuckyTemplates Tip: How To Compare First N Business Days

LuckyTemplates Tip: How To Compare First N Business Days

Creating A Custom Column

Next, we need to create a custom column to add the count that we need for the business days.

LuckyTemplates Tip: How To Compare First N Business Days

We’re going to use a function called Table.AddIndexColumn, which will operate on the AllRows table, and we’ll call it Day Index. We want the index to start with 1, and increment by 1 with each new business day.

LuckyTemplates Tip: How To Compare First N Business Days

Then we can remove the first three columns, and expand on our fourth custom column.

LuckyTemplates Tip: How To Compare First N Business Days

LuckyTemplates Tip: How To Compare First N Business Days

If we look at the result, it gives us the day index, which counts the business days (true), and then counts the days that are weekends and holidays in each month (false). Next, we have to check that these are in their proper field type.

LuckyTemplates Tip: How To Compare First N Business Days

Let’s go back to our Sales table. We’ll merge the Aggregate table that we just created with our Sales table.

LuckyTemplates Tip: How To Compare First N Business Days

We’ll merge those on the OrderDate. You can see at the bottom that it matches all the rows from the first table.

LuckyTemplates Tip: How To Compare First N Business Days

When we expand the Sales Agg column, select the new fields that we just added: the Month & Year, DayOfWeekName, MonthnYear, IsBusinessDay, and DayIndex columns.

Let’s also clean up our data before we click on Close & Apply. Let’s move the Sales Agg table in our Data Prep section, then unload that table since we’re not going to need it within the data model. Then click on Close & Apply.

Our power query prep work is now done.

LuckyTemplates Tip: How To Compare First N Business Days

Creating A What-If Parameter

Remember that in the original task we want to vary the number of days that we look at from 5 to 10 and 15 to 20. I think the best way to do this is with a new what-if parameter.

We’ll call the what-if parameter First N Business Days and its data type will be a whole number. The minimum is set to an increment of 1 and a maximum of 20. Then we’ll default to 5, which is the first value that the user wanted.

LuckyTemplates Tip: How To Compare First N Business Days

We now have a slicer that automatically creates the harvest measure to capture the slicer value.

LuckyTemplates Tip: How To Compare First N Business Days

Let’s create a table with our results. Let’s put our Month & Year dimension in the canvas and then sort it by Month & Year.

LuckyTemplates Tip: How To Compare First N Business Days

Once we have this field properly sorted, we can just drop the Total Sales measure and expand it out.

LuckyTemplates Tip: How To Compare First N Business Days

Creating A Measure For Number Of Business Days

We need to create one more measure that takes a look at the value of the slider parameter and only calculates for the number of business days.

LuckyTemplates Tip: How To Compare First N Business Days

We’ll call this new measure Total Sales N Bus Days. We’ll start with the function since we’re definitely changing context, and with our Total Sales measure. We’re going to filter this with the of our Sales table.

LuckyTemplates Tip: How To Compare First N Business Days

The next step is to write the conditions that we want to take into account for the slider. We have our Sales Day Index that we created in Power Query, and we want this to be less than or equal to the First N Business Days value, which is the harvested value of the slicer.

For example, if the slider is at 5, we want all the days of the Sales table where the day index is less than or equal to 5.

LuckyTemplates Tip: How To Compare First N Business Days

And then we want to take out the non-business days. We’ll reference the Date table and use the IsBusinessDay field. We’ll only look at the result that is TRUE.

LuckyTemplates Tip: How To Compare First N Business Days

Lastly, bring the context back for Month & Year and close out the measure. We should be good to go at this point.

LuckyTemplates Tip: How To Compare First N Business Days

Let’s drop the new measure into our table.

LuckyTemplates Tip: How To Compare First N Business Days

We can take the slider slicer to the 10 day-mark, and the table will dynamically calculate at the 10-day mark.

LuckyTemplates Tip: How To Compare First N Business Days

Conclusion

In this LuckyTemplates tip, we talked about how to do a like-for-like comparison dynamically using a Power Query solution. We can put this into a bar chart or a line chart.

In some of our upcoming tutorials, we’ll take a look at the DAX solution and implement the visualization of the KPI scroller.

If you enjoyed the content covered in this particular tutorial, please don’t forget to subscribe to the LuckyTemplates TV channel.


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.

LuckyTemplates Kullanarak İş Raporlaması

LuckyTemplates Kullanarak İş Raporlaması

Şimdiye kadar hala Excel kullanıyorsanız, iş raporlama ihtiyaçlarınız için LuckyTemplates'ı kullanmaya başlamak için en iyi zaman budur.

LuckyTemplates Ağ Geçidi Nedir? Bilmen gereken her şey

LuckyTemplates Ağ Geçidi Nedir? Bilmen gereken her şey

LuckyTemplates Ağ Geçidi Nedir? Bilmen gereken her şey