Temporal Scale Using Calculated Columns In LuckyTemplates

Every so often we’ll be needing the availability of a custom visual of a bar chart or line chart that gives an option to plot the chart either weekly, monthly, quarterly, or yearly. In this tutorial, I’m going to demonstrate how you can create a dynamic temporal scale, using calculated columns that can let you change the level of granularity depending on your date or time basis. You can watch the full video of this tutorial at the bottom of this blog.

A temporal scale allows you to show a granular level of detail at the most important current information. It shows less granularity for previous dates.

Temporal Scale Using Calculated Columns In LuckyTemplates

This is useful in a lot of cases. I’ve seen this in manufacturing, for example, they want to get a long history of the information. This allows them to display a lot more information on the screen and get the whole history of what’s going on. But for the current quarter, it allows them to see exactly what’s going on at a level of detail by week.

Table of Contents

How To Create A Dynamic Temporal Scale

As you can see here, I’ve got my R10 Date table, where I’m just using the calendar function for 2016 to today. And then, I’m randomly generating some inventory levels.

Temporal Scale Using Calculated Columns In LuckyTemplates

The first step is to create this IsCurrentQuarter. There are different ways of doing this. In this measure, I’m grabbing what is the date today, what is my current year, and my current quarter. And then, I’m grabbing the year of the current row I’m in, driving the quarter of the current row I’m in.

If the year matches the current year and the quarter matches the current quarter, return true. Otherwise, return false. So that’s all that this does. For any date in the current quarter, it’s going to return true. As we get past the current quarter, we’re going to start returning false.

Temporal Scale Using Calculated Columns In LuckyTemplates

The next step is to create what I’m calling the DTS Column, which is pretty simple. All we’re doing is saying if it’s the current quarter, then we’re going to return a value that starts with the letter W for week. We grab the weeknum of the current row’s date, and we grab the year, and then we put it in this format, e.g. W16-2022.

And then once we start going back past the current quarter, if it’s not in the current quarter, then we’re returning just the Q for quarter, then the quarter and the year. So, we’ll have Q1-2022, Q2-2022, etc.

Temporal Scale Using Calculated Columns In LuckyTemplates

The last step is that we need to sort this correctly. We’re going to do something similar and we’re going to create this DTS Sort By column. And again, we’re just checking if it’s the current year. If it is, then we return a value of just the year, the quarter, and then the week number. If it’s not in the current quarter, we return just the year and the quarter.

Temporal Scale Using Calculated Columns In LuckyTemplates

Then we would set this sort by column to be our DTS Sort By column.

Temporal Scale Using Calculated Columns In LuckyTemplates

Once we do that, then we can use the DTS column on our X-axis. So, here our X-axis is the DTS. Our Y-axis is the Average of the Inventory. The other nice thing about having that calculated column is that we can use that to differentiate the colors on this column chart, for example. So, I can use the IsCurrentQuarter as my legend.

Temporal Scale Using Calculated Columns In LuckyTemplates


See Changing Results Using Calculated Columns In LuckyTemplates
Comparing Calculated Columns And Measures In LuckyTemplates
Calculated Table And Column In Tabular Editor 3

Conclusion

You could extend this dynamic temporal scale technique with a few additional columns. Let’s say, if it’s the current week, you want to show it by day. If it’s the current month, show it by week. If it’s the current quarter, show it by month, and if it’s the current year, show it by quarter. And then if it’s been past years, just show up by a year, for example. So, you can have a lot of different variations on how you can do this.

If you added additional columns, you’d need a few additional columns to get different levels of granularity, like to the day, to the month, week, and year. But all are possible using the same technique, you just need a little extra DAX code.

Probably we would replace this IF with a SWITCH statement because otherwise we’re going to get into Nested IFs and nobody likes those.

A downside to implementing this as quarters is that you’re adding data into your data model and all the ills that people claim with calculated columns (which I agree with, some of which I don’t).

But it’s not that bad. There’s not a high level of cardinality with these additional columns that we have here. This only has just one or two values. It’s not like we are adding thousands of unique items with these different columns that we have.

This is probably the most straightforward way to implement this dynamic temporal scale. I hope this has been valuable. Check out the links below for more related content.

All the best!

Greg




***** Related Support Forum Posts *****



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.