Close Menu
    Trending
    • Optimizing Data Transfer in Distributed AI/ML Training Workloads
    • Achieving 5x Agentic Coding Performance with Few-Shot Prompting
    • Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found
    • From Transactions to Trends: Predict When a Customer Is About to Stop Buying
    • America’s coming war over AI regulation
    • “Dr. Google” had its issues. Can ChatGPT Health do better?
    • Evaluating Multi-Step LLM-Generated Content: Why Customer Journeys Require Structural Metrics
    • Why SaaS Product Management Is the Best Domain for Data-Driven Professionals in 2026
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Does Calendar-Based Time-Intelligence Change Custom Logic?
    Artificial Intelligence

    Does Calendar-Based Time-Intelligence Change Custom Logic?

    ProfitlyAIBy ProfitlyAIJanuary 20, 2026No Comments9 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Introduction

    calendar-based Time Intelligence, the necessity for customized Time Intelligence logic has decreased dramatically.

    Now, we are able to create customized calendars to fulfill our Time Intelligence calculation wants.

    You might need learn my article about superior Time Intelligence:

    https://towardsdatascience.com/advanced-time-intelligence-in-dax-with-performance-in-mind/

    Many of the customized logic is not wanted.

    However we nonetheless have eventualities the place we should have customized calculations, like operating common.

    A while in the past, SQLBI wrote an article about calculating the operating common.

    This piece makes use of the identical rules described there in a barely completely different method.

    Let’s see how we are able to calculate the operating common over three months by utilizing the brand new Calendars.

    Utilizing basic Time Intelligence

    First, we use the usual Gregorian calendar with the basic Time Intelligence date desk.

    I exploit the same method as described within the SQLBI article linked within the References part beneath.

    Operating Common by Month = 
    // 1. Get the primary and final Date for the present Filter Context
    VAR MaxDate = MAX( 'Date'[Date] )
    
    
    // 2. Generate the Date vary wanted for the Shifting common (three months)
    VAR  DateRange =
     DATESINPERIOD( 'Date'[Date]
            ,MaxDate
            ,-3
            ,MONTH
        )
    
    // 3. Generate a desk filtered by the Date Vary generated at step 2
    // This desk comprises solely three rows
    VAR SalesByMonth = 
        CALCULATETABLE(
            SUMMARIZECOLUMNS(
                'Date'[MonthKey]
                , "#Gross sales", [Sum Online Sales]
                
            )
            ,DateRange
        )
    
    RETURN
        // 4. Calculate the Common over the three values within the desk generate in step 3
        AVERAGEX(SalesByMonth, [#Sales])
    

    When executing this measure in DAX Studio, I get the anticipated outcomes:

    Determine 1 – Operating Common over three months with the basic Time Intelligence method (Determine by the Creator)

    To date, so good.

    Utilizing an ordinary calendar

    Subsequent, I created a Calendar named “Gregorian Calendar” and adjusted the code to make use of this calendar.

    To make this simpler to know, I copied the date desk to a brand new desk named “Gregorian Date Desk”.

    The change is when calling the DATESINPERIOD() perform.

    As a substitute of utilizing the date column, I exploit the newly created calendar:

    Operating Common by Month = 
    // 1. Get the primary and final Date for the present Filter Context
    VAR MaxDate = MAX( 'Gregorian Date Desk'[Date] )
    
    
    // 2. Generate the Date vary wanted for the Shifting common (three months)
    VAR  DateRange =
     DATESINPERIOD( 'Gregorian Calendar'
            ,MaxDate
            ,-3
            ,MONTH
        )
    
    
    
    // 3. Generate a desk filtered by the Date Vary generated at step 2
    // This desk comprises solely three rows
    VAR SalesByMonth = 
        CALCULATETABLE(
            SUMMARIZECOLUMNS(
                'Gregorian Date Desk'[MonthKey]
                , "#Gross sales", [Sum Online Sales]
                
            )
            ,DateRange
        )
    
    RETURN
        // 4. Calculate the Common over the three values within the desk generate in step 3
        AVERAGEX(SalesByMonth, [#Sales])
    

    As anticipated, the outcomes are similar:

    Determine 2 – Identical Outcome as earlier than when utilizing the Calendar (Determine by the Creator)

    The efficiency is superb, as this question completes in 150 milliseconds.

    Utilizing a customized calendar

    However what occurs when utilizing a customized calendar?

    For instance, a calendar with 15 months per 12 months and 31 days for every month?

    I created such a calendar for my article, which describes use instances for calendar-based Time Intelligence (See the Hyperlink on the High and within the References part).

    Whenever you take a look at the code for the measure, you’ll discover that it’s completely different:

    Operating Common by Month (Customized) = 
        VAR LastSelDate = MAX('Monetary Calendar'[CalendarEndOfMonthDate])
    
        VAR MaxDateID = CALCULATE(MAX('Monetary Calendar'[ID_Date])
                                    ,REMOVEFILTERS('Monetary Calendar')
                                    ,'Monetary Calendar'[CalendarEndOfMonthDate] = LastSelDate
                                    )
    
        VAR MinDateID = CALCULATE(MIN('Monetary Calendar'[ID_Date])
                                    ,REMOVEFILTERS('Monetary Calendar')
                                    ,'Monetary Calendar'[CalendarEndOfMonthDate] = EOMONTH(LastSelDate, -2)
                                    )
    
        VAR SalesByMonth = 
            CALCULATETABLE(
                SUMMARIZECOLUMNS(
                    'Monetary Calendar'[CalendarYearMonth]
                    , "#Gross sales", [Sum Online Sales]
                    
                )
                ,'Monetary Calendar'[ID_Date] >= MinDateID
                    && 'Monetary Calendar'[ID_Date] <= MaxDateID
            )
    
        RETURN
        AVERAGEX(SalesByMonth, [#Sales])

    The explanation for the modifications is that this desk lacks a date column usable with the DATESINPERIOD() perform. For that reason, I have to use customized code to calculate the worth vary for ID_Date.

    These are the outcomes:

    Determine 3 – Outcomes of the operating common when utilizing a customized calendar with no Dates (Determine by the Creator)

    As you’ll be able to test, the outcomes are appropriate.

    Optimizing by utilizing a day index

    However once I analyze the efficiency, it’s not that nice.

    It takes virtually half a second to calculate the outcomes.

    We will enhance efficiency by eradicating the necessity to retrieve the minimal and most ID_Date and performing a extra environment friendly calculation.

    I do know that every month has 31 days.

    To return three months, I do know that I have to return by 93 days.

    I can use this to create a sooner model of the measure:

    Operating Common by Month (Monetary) = 
        // Step 1: Get the final Month (ID)
        VAR SelMonth = MAX('Monetary Calendar'[ID_Month])
        
        // Step 2: Generate the Date Vary from the final 93 days
        VAR DateRange =
            TOPN(93
            ,CALCULATETABLE(
                        SUMMARIZECOLUMNS('Monetary Calendar'[ID_Date])
                        ,REMOVEFILTERS('Monetary Calendar')
                        ,'Monetary Calendar'[ID_Month] <= SelMonth
                    )
                    ,'Monetary Calendar'[ID_Date], DESC
                )
        
        
        // 3. Generate a desk filtered by the Date Vary generated at step 2
        // This desk comprises solely three rows
        VAR SalesByMonth = 
            CALCULATETABLE(
                SUMMARIZECOLUMNS(
                    'Monetary Calendar'[ID_Month]
                    , "#Gross sales", [Sum Online Sales]
                    
                )
                ,DateRange
            )
        
        RETURN
            // 4. Calculate the Common over the three values within the desk generate in step 3
            AVERAGEX(SalesByMonth, [#Sales])
    

    This time, I used the TOPN() perform to retrieve the 93 earlier rows from the Monetary Calendar desk and used this record as a filter.

    The outcomes are similar to the earlier model:

    Determine 4 – Outcomes of the Model which makes use of the final 93 days (Determine by the Creator)

    This model wants solely 118 ms to finish.

    However can we go even additional with the optimization?

    Subsequent, I added a brand new column to the Fiscal Calendar to assign ranks to the rows. Now, every date has a singular quantity which is in direct correlation to the order of them:

    Determine 5 – Extract from the Monetary Calendar desk with the RowRank column (Determine by the Creator)

    The measure utilizing this column is the next:

    Operating Common by Month (Monetary) = 
        // Step 1: Get the final Month (ID)
        VAR MaxDateRank = MAX('Monetary Calendar'[ID_Date_RowRank])
        
        // Step 2: Generate the Date Vary from the final 93 days
        VAR DateRange =
                CALCULATETABLE(
                            SUMMARIZECOLUMNS('Monetary Calendar'[ID_Date])
                            ,REMOVEFILTERS('Monetary Calendar')
                            ,'Monetary Calendar'[ID_Date_RowRank] <= MaxDateRank
                                && 'Monetary Calendar'[ID_Date_RowRank] >= MaxDateRank - 92
                        )
                        --ORDER BY 'Monetary Calendar'[ID_Date] DESC
        
        
        // 3. Generate a desk filtered by the Date Vary generated at step 2
        // This desk comprises solely three rows
        VAR SalesByMonth = 
            CALCULATETABLE(
                SUMMARIZECOLUMNS(
                    'Monetary Calendar'[ID_Month]
                    , "#Gross sales", [Sum Online Sales]
                    
                )
                ,DateRange
            )
        
        RETURN
            // 4. Calculate the Common over the three values within the desk generate in step 3
            AVERAGEX(SalesByMonth, [#Sales])
    

    The outcome is similar, I don’t present it once more.

    However right here is the comparability from the execution statistics:

    Determine 6 – Execution statistics of the 2 Measures. On prime, you see the statistics for the one utilizing TOPN(). Beneath are the statistics for the one utilizing the RowRank column (Determine by the Creator)

    As you’ll be able to see, the Model utilizing TOPN() is barely slower than the one utilizing the RowRank column.

    However the variations are marginal.

    Extra importantly, the model utilizing the RowRank column requires extra information to finish the calculations. See the Rows column for particulars.

    This implies extra RAM utilization.

    However with this small variety of rows, the variations are nonetheless marginal.

    It’s your selection which model you like.

    Utilizing a weekly calendar

    Lastly, let’s take a look at a week-based calculation.

    This time, I need to calculate the rolling common over the past three weeks.

    Because the calendar-based Time Intelligence permits for the creation of a week-based calendar, the measure is similar to the second:

    Operating Common by Week = 
    // 1. Get the primary and final Date for the present Filter Context
    VAR MaxDate = MAX( 'Gregorian Date Desk'[Date] )
    
    
    // 2. Generate the Date vary wanted for the Shifting common (three months)
    VAR  DateRange =
     DATESINPERIOD( 'Week Calendar'
            ,MaxDate
            ,-3
            ,WEEK
        )
    
    
    
    // 3. Generate a desk filtered by the Date Vary generated at step 2
    // This desk comprises solely three rows
    VAR SalesByMonth = 
        CALCULATETABLE(
            SUMMARIZECOLUMNS(
                'Gregorian Date Desk'[WeekKey]
                , "#Gross sales", [Sum Online Sales]
                
            )
            ,DateRange
        )
    
    RETURN
        // 4. Calculate the Common over the three values within the desk generate in step 3
        AVERAGEX(SalesByMonth, [#Sales])
    

    The important thing half is that I exploit the “WEEK” parameter within the DATESINPERIOD() name.
    That’s all.

    That is the results of the question:

    Determine 7 – Outcome for the operating common over three weeks (Determine by the Creator)

    The efficiency is superb, with execution instances beneath 100 ms.

    Remember that weekly calculations are solely doable with the calendar-based Time Intelligence.

    Conclusion

    As you will have seen, the calendar-based Time Intelligence makes life simpler with customized logic: we solely must go the calendar as a substitute of a date column to the capabilities. And we are able to calculate weekly intervals.

    However the present function set doesn’t embrace a semester interval. After we should calculate semester-based outcomes, we should both use basic Time Intelligence or write customized code.

    However we nonetheless want customized logic, particularly once we don’t have a date column in our calendar desk. In such instances, we are able to’t use the usual time intelligence capabilities, as they nonetheless work with date columns.

    Bear in mind: Crucial process when working with calendar-based Time Intelligence is constructing a constant and full calendar desk. From my expertise, that is essentially the most advanced process.

    As a sidenote, I discovered some attention-grabbing capabilities on daxlib.org a couple of operating common.

    I added a hyperlink to the capabilities within the References part beneath.

    These capabilities observe a totally completely different sample, however I wished to incorporate them to create a whole image of this subject.

    References

    The talked about SQLBI.com article on calculating the operating Common:

    https://www.sqlbi.com/articles/rolling-12-months-average-in-dax

    Time Sequence capabilities on daxlib.org with a special method:

    https://daxlib.org/package/TimeSeries.MovingAverage

    Right here is my final article, the place I clarify Calendar-based Time-Intelligence:

    https://towardsdatascience.com/use-cases-for-the-new-calendar-based-time-intelligence/

    Like in my earlier articles, I exploit the Contoso pattern dataset. You’ll be able to obtain the ContosoRetailDW Dataset without cost from Microsoft here.

    The Contoso Information can be utilized freely below the MIT License, as described in this document. I modified the dataset to shift the info to up to date dates.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleThe era of agentic chaos and how data will save us
    Next Article Why it’s critical to move beyond overly aggregated machine-learning metrics | MIT News
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026
    Artificial Intelligence

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026
    Artificial Intelligence

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    How to Create an AI-Powered Search Strategy with Wil Reynolds [MAICON 2025 Speaker Series]

    August 21, 2025

    From Classical Models to AI: Forecasting Humidity for Energy and Water Efficiency in Data Centers

    November 2, 2025

    How to Use LLMs for Powerful Automatic Evaluations

    August 13, 2025

    Do You Smell That? Hidden Technical Debt in AI Development

    January 15, 2026

    Past is Prologue: How Conversational Analytics Is Changing Data Work

    October 9, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    Transformers (and Attention) are Just Fancy Addition Machines

    July 24, 2025

    Test: ChatGPT vs Googles Imagen 4 vs FLUX 1.1 – Vilken AI-bildgenerator är bäst?

    June 9, 2025

    Inside the Trump Administration’s New AI Action Plan

    July 29, 2025
    Our Picks

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.