skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
    • Getting started
      • Overview
      • Online workshops
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • Happy Easter

    Happy Easter

    03-31-2022 13:56 PM - last edited 03-31-2022 14:06 PM

    Super User Greg_Deckler
    Super User
    348 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Happy Easter

    ‎03-31-2022 01:56 PM

    Calculates Easter for years 1583 - 4099. Code adapted from https://www.assa.org.au/edm. Also, PBIX includes an IsEaster column with a slightly different RETURN clause. Inspired by a conversation with Power BI Guy: Connect Live with Greg Deckler - YouTube

     

    Easter = 
        // Original code: https://www.assa.org.au/edm
        // For years 1583 to 4099
        VAR __Date = MAX('Date'[Date])
        VAR __Year = YEAR(__Date)
        VAR __Month = MONTH(__Date)
        VAR __Day = DAY(__Date)
        VAR __FirstDigit = TRUNC(__Year/100)
        VAR __Remainder19 = MOD(__Year, 19)
        VAR __PFMDate1 = TRUNC((__FirstDigit - 15) / 2) + 202 - 11 * __Remainder19
        VAR __PFMDate2 = 
            SWITCH(TRUE(),
                __FirstDigit IN {21, 24, 25, 27, 28, 29, 30, 31, 32, 34, 35, 38}, __PFMDate1 - 1,
                __FirstDigit IN {33, 36, 37, 39, 40}, __PFMDate1 - 2,
                __PFMDate1
            )
        VAR __PFMDate = MOD(__PFMDate2, 30)
        VAR __tA = 
            SWITCH(TRUE(),
                __PFMDate = 29 || (__PFMDate = 29 && __Remainder19 > 10), __PFMDate + 20,
                __PFMDate + 21
            )
        VAR __tB = MOD(__tA - 19, 7)
        VAR __tC1 = MOD(40 - __FirstDigit, 4)
        VAR __tC2 = IF(__tC1 = 3, __tC1 + 1, __tC1)
        VAR __tC = IF(__tC2 > 1, __tC2 + 1, __tC2)
        VAR __tD1 = MOD(__Year,100)
        VAR __tD = MOD( __tD1 + TRUNC(__tD1/4), 7)
        VAR __tE = MOD(20 - __tB - __tC - __tD, 7) + 1
        VAR __d = __tA + __tE
        VAR __EasterDay = IF(__d > 31, __d - 31, __d)
        VAR __EasterMonth = IF(__d > 31, 4, 3)
        VAR __EasterYear = __Year
    RETURN
        DATE(__EasterYear, __EasterMonth, __EasterDay)

     

    Also, the MSHGQM version:

     

     

    Easter = 
        // Original code: https://www.assa.org.au/edm
        // For years 1583 to 4099
        VAR __Date = __AGGREGATION__(__COLUMN__)
        VAR __Year = YEAR(__Date)
        VAR __Month = MONTH(__Date)
        VAR __Day = DAY(__Date)
        VAR __FirstDigit = TRUNC(__Year/100)
        VAR __Remainder19 = MOD(__Year, 19)
        VAR __PFMDate1 = TRUNC((__FirstDigit - 15) / 2) + 202 - 11 * __Remainder19
        VAR __PFMDate2 = 
            SWITCH(TRUE(),
                __FirstDigit IN {21, 24, 25, 27, 28, 29, 30, 31, 32, 34, 35, 38}, __PFMDate1 - 1,
                __FirstDigit IN {33, 36, 37, 39, 40}, __PFMDate1 - 2,
                __PFMDate1
            )
        VAR __PFMDate = MOD(__PFMDate2, 30)
        VAR __tA = 
            SWITCH(TRUE(),
                __PFMDate = 29 || (__PFMDate = 29 && __Remainder19 > 10), __PFMDate + 20,
                __PFMDate + 21
            )
        VAR __tB = MOD(__tA - 19, 7)
        VAR __tC1 = MOD(40 - __FirstDigit, 4)
        VAR __tC2 = IF(__tC1 = 3, __tC1 + 1, __tC1)
        VAR __tC = IF(__tC2 > 1, __tC2 + 1, __tC2)
        VAR __tD1 = MOD(__Year,100)
        VAR __tD = MOD( __tD1 + TRUNC(__tD1/4), 7)
        VAR __tE = MOD(20 - __tB - __tC - __tD, 7) + 1
        VAR __d = __tA + __tE
        VAR __EasterDay = IF(__d > 31, __d - 31, __d)
        VAR __EasterMonth = IF(__d > 31, 4, 3)
        VAR __EasterYear = __Year
    RETURN
        DATE(__EasterYear, __EasterMonth, __EasterDay)

     

     

     

    eyJrIjoiMmY1MjNiYWQtYzhmMS00MzE0LTlkMzItNTU0NzI1NWEzMzY3IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Easter.pbix
    Labels:
    • Labels:
    • Time Intelligence
    Message 1 of 1
    348 Views
    0
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices