Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • How small businesses can leverage AI
    • Robots-Blog | Humanoide Robotik aus Deutschland: igus bringt neuen Serviceroboter auf den Markt
    • GM reimagines Hummer off-roader with California ideas unit
    • London’s DEScycle secures over €10 million in grant funding to scale critical metals recovery platform
    • How to Edit, Merge, and Split PDFs With Free Online Tools
    • Florida crackdown targets illegal machines in Sarasota
    • Audiophile-Oriented Noble Audio Debuts More Affordable Osprey Earbuds
    • New radio bursts detected from binary stars
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Tuesday, June 2
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»Under the Hood: How DAX Works with Filters
    Artificial Intelligence

    Under the Hood: How DAX Works with Filters

    Editor Times FeaturedBy Editor Times FeaturedOctober 1, 2025No Comments7 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    Let’s begin with a easy desk:

    Determine 1 – The easy desk to start out with (Determine by the Creator)

    Every row within the matrix visible reveals the whole on-line gross sales for every month.
    To date, so good.

    The interpretation is that we see the whole on-line gross sales filtered by month.

    However this isn’t your entire reality.

    Let’s check out the information mannequin:

    Determine 2 – The a part of the information mannequin with the Date desk and the actual fact desk (Determine by the Creator)

    Once you look rigorously, you see that the connection is constructed between the 2 date columns.

    There isn’t a relationship to the month column.

    Once we take this route, the interpretation above just isn’t totally correct.

    The whole interpretation must be: Every row reveals the whole of on-line gross sales filtered by the date desk. The rows of the Date desk are grouped by the months. Every row reveals the whole gross sales for all days for every month.

    We’re a step nearer to understanding DAX normally, and time intelligence features particularly, once we notice this element.

    Let’s go one step additional.

    YTD and the Fundamental question

    Now, let’s add a YTD Measure to look at what occurs:

    Determine 3 – The YTD Measure and the outcomes are in the identical desk as earlier than (Determine by the Creator)

    The Measure is nothing particular, and the outcomes are straightforward to grasp.

    Now, let’s check out what exactly the DATESYTD() perform does.

    The reason from dax.guide says: “Returns a set of dates within the 12 months as much as the final date seen within the filter context”.

    What does this imply precisely?

    To dive into this query, let’s write a DAX question first, to get the listing of dates in June 2024, as is finished within the visualization above:

    DEFINE
        VAR YearFilter = TREATAS({ 2024 }, 'Date'[Year])
        VAR MonthFilter = TREATAS({ 6 }, 'Date'[Month])
        
        
    EVALUATE
        SUMMARIZECOLUMNS('Date'[Date]
                            ,YearFilter
                            ,MonthFilter
                            )

    The result’s a listing of 30 days for June:

    Determine 4 – Foundation Question to get all days for June 2024 (Determine by the Creator)

    That is the filter utilized to the row for June 2024 within the Matrix proven above.

    What’s the outcome once we apply the DATESYTD() perform to the outcome?

    Right here is the question:

    DEFINE
        VAR YearFilter = TREATAS({ 2024 }, 'Date'[Year])
        VAR MonthFilter = TREATAS({ 6 }, 'Date'[Month])
        
        VAR BasisDates = CALCULATETABLE(
                                SUMMARIZECOLUMNS('Date'[Date]
                                            ,YearFilter
                                            ,MonthFilter
                                            )
                                        )
        
        VAR YTDDates = DATESYTD(TREATAS(BasisDates, 'Date'[Date])
                                        )
                                        
    EVALUATE
        YTDDates

    And right here, the outcome:

    Determine 5 – Listing of dates beginning on the primary of January as much as the final day of June 2024 (Determine by the Creator)

    It’s a listing of 182 rows, containing all dates ranging from the start of the 12 months as much as the final day of June 2024.

    That is the definition of YTD.

    Once we take a look at the next Measure:

    On-line Gross sales (YTD) =
    VAR YTDDates = DATESYTD('Date'[Date])
    
    RETURN
        CALCULATE([Sum Online Sales]
                    ,YTDDates
                    )

    We notice that the variable YTDDates is “solely” a listing of dates utilized as a filter to the CALCULATE() perform.

    That is the important thing to all Time intelligence features.

    Return one 12 months – some examples

    What occurs when making use of one other perform to the outcome?

    For instance, SAMEPERIODLASTYEAR()?

    To reply this query, I take advantage of the next DAX question:

    DEFINE
        VAR YearFilter = TREATAS({ 2024 }, 'Date'[Year])
        VAR MonthFilter = TREATAS({ 6 }, 'Date'[Month])
        
        VAR BasisDates = CALCULATETABLE(
                                SUMMARIZECOLUMNS('Date'[Date]
                                            ,YearFilter
                                            ,MonthFilter
                                            )
                                        )
        
        VAR YTDDates = DATESYTD(TREATAS(BasisDates, 'Date'[Date])
                                        )
                                        
        VAR YTDDatesPY = SAMEPERIODLASTYEAR(YTDDates)
                                        
    EVALUATE
        YTDDatesPY

    I deliberately separated the calling of SAMEPERIODLASTYEAR() from DATESYTD() to make it simpler to learn. It could have been attainable to nest DATESYTD() into SAMEPERIODLASTYEAR().

    This time, we’ve got 181 rows, as 2024 was a bissextile year.
    And the dates are shifted again by one 12 months:

    Determine 6 – The results of the question after making use of SAMEPERIODLASTYEAR() (Determine by the Creator)

    So, once more, once we apply a Time Intelligence perform to a measure, the perform, for instance, DATESYTD(), returns a listing of dates.
    Please notice: When making use of the filter, any present filters on the date desk are eliminated.

    Customized logic

    Now, let’s use this information on customized time intelligence logic.

    First, let’s barely change the filter for the 12 months and month:

    DEFINE
        VAR YearMonthFilter = TREATAS({ 202406  }, 'Date'[MonthKey])
        
    EVALUATE
        SUMMARIZECOLUMNS('Date'[Date]
                            , YearMonthFilter
                            )

    The results of this question is similar as initially of this text.

    This time, I set the filter with a numerical worth on the [MonthKey] column.

    How can I’m going again to the earlier 12 months?

    In the event you suppose mathematically, it’s simply by subtracting 100:

    202406 – 100 = 202306

    Let’s strive it:

    Determine 7 – The results of the question after deducting 100 from the [MonthKey] column (Determine by the Creator)

    It’s also possible to do that with different numeric codecs.

    Once you take a fiscal 12 months, for instance, like this: 2425 (For the Fiscal Yr 24/25)

    You’ll be able to deduce 101 to get the earlier fiscal 12 months: 2425 – 101 = 2324

    One other instance of a customized time intelligence logic is a operating common, the place for every day, we calculate the typical worth over the previous 10 days:

    Determine 8 – The Code and the outcomes of the Measure for a transferring common over the earlier ten days (Determine by the Creator)

    Because the content material of the variable DateRange is once more a listing of dates, I can apply the SAMEPERIODLASTYEAR() perform to it, and get the outcome I want:

    DEFINE
        VAR YearFilter = TREATAS({ 2024 }, 'Date'[Year])
        VAR MonthFilter = TREATAS({ 6 }, 'Date'[Month])
        
        // 1. Get the primary and final Date for the present Filter Context
        VAR MaxDate = CALCULATE(MAX( 'Date'[Date] )
                                ,YearFilter
                                ,MonthFilter
                                )
        
        VAR MinDate =
            CALCULATE(
                DATEADD( 'Date'[Date], - 10, DAY )
                ,'Date'[Date] = MaxDate
                )
        
        // 2. Generate the Date vary wanted for the Shifting common (4 months)
        VAR  DateRange =
         CALCULATETABLE(
            DATESBETWEEN( 'Date'[Date]
                ,MinDate
                ,MaxDate
            )
        )
        
    EVALUATE
        SAMEPERIODLASTYEAR( DateRange )

    And that is the outcome:

    Determine 9 – The outcome for the transferring common for the earlier 12 months (Determine by the Creator)

    This logic returns 11 rows, because it consists of the final day of the month. Relying on the required outcome, we have to regulate the best way we calculate the primary and final dates of the date listing (the filter utilized to the measure).

    After all, it is a repetition of what I confirmed above. Nevertheless, it demonstrates that the identical strategy will be utilized to varied situations.

    As quickly as you perceive this, your work with time intelligence features and different features that settle for tables of values as enter will turn out to be a lot simpler to understand and grasp.

    Conclusion

    Whereas I used DAX Studio for the queries, you should utilize the identical queries within the DAX Question instrument inside Energy BI Desktop.

    I deliberately used these queries to reveal that we work with tables on a regular basis in DAX, though we might not all the time concentrate on it.

    However it’s an necessary element that helps us on our technique to understanding DAX.

    Though a number of the DAX code proven right here could also be out of date with the arrival of the brand new calendar-based time intelligence characteristic in Energy BI, the ideas defined right here stay legitimate. The features, equivalent to DATESYTD() or SAMEPERIODLASTYEAR(), nonetheless exist and work in the identical means as earlier than. In the interim, nothing will change on this aspect, because the ideas described listed below are nonetheless legitimate.

    References

    Like in my earlier articles, I take advantage of the Contoso pattern dataset. You’ll be able to obtain the ContosoRetailDW Dataset at no cost from Microsoft here.

    The Contoso Knowledge will be freely used underneath the MIT License, as described in this document. I modified the dataset to shift the information to modern dates.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    Escaping the Valley of Choice in BI

    June 2, 2026

    Ensuring Data Integrity with Cryptographic Hashing and the Ethereum Blockchain

    June 1, 2026

    RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem

    June 1, 2026

    How to Combine Claude Code and Codex for Maximum Coding Power

    June 1, 2026

    It’s the Lessons We Learned Along the Way. Or, Is It?

    June 1, 2026

    Proxy-Pointer RAG: Eliminating Wasteful Entity & Relations Extraction in Knowledge Graphs

    May 31, 2026

    Comments are closed.

    Editors Picks

    How small businesses can leverage AI

    June 2, 2026

    Robots-Blog | Humanoide Robotik aus Deutschland: igus bringt neuen Serviceroboter auf den Markt

    June 2, 2026

    GM reimagines Hummer off-roader with California ideas unit

    June 2, 2026

    London’s DEScycle secures over €10 million in grant funding to scale critical metals recovery platform

    June 2, 2026
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    Kalshi backtracks on student ambassador program after backlash

    September 23, 2025

    US Trade Dominance Will Soon Begin to Crack

    December 26, 2025

    Zoox ramps up robotaxi production for Las Vegas launch

    June 20, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

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