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
    • Dynamics 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
      • 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
    • Microsoft Power BI Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power BI
    • Desktop
    • Service
    • Report Server
    • Power Query
    • Mobile Apps
    • Developer
    • DAX Commands and Tips
    • Custom Visuals Development Discussion
    • Health and Life Sciences
    • Power BI Spanish Community
    • Translated Spanish Desktop
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Training and Consulting
    • Instructor Led Training
    • 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
    • Ideas
    • Custom Visuals Ideas
    • Issues
    • Issues
    • Events
    • Upcoming Events
    • Community Engagement
    • T-Shirt Design Challenge 2023
    • Community Blog
    • Power BI Community Blog
    • Custom Visuals Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    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
    • DAX Custom 445 Calendar

    DAX Custom 445 Calendar

    09-22-2020 17:06 PM

    Super User Greg_Deckler
    Super User
    3754 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

    DAX Custom 445 Calendar

    ‎09-22-2020 05:06 PM

    Thanks to a request by @dogt1225 from this thread comes this highly configurable DAX Custom 445 Calendar. Now, this is certainly not the first custom calendar nor will it be the last but it is one that I created and I think it is notable because of how easily configurable it is to customize for your own needs. In this instance, the calendar is configured for weeks starting on Saturday and ending on Friday starting on the 5th Saturday of the year 2020 for 2 years.

     

    Additional features of this calendar include assigning a week # of the year, week # of the quarter, sequential week #, quarter, month, day of year, etc.

    Custom445 = 
        VAR __StartYear = 2020 // starting year
        VAR __NumYears = 2 // number of years including start year
        VAR __WeekForm = 16 // 16 has Saturday as 1, Friday 7
        VAR __StartDay = 1 // weekday to start calendar on
        VAR __StartWeek = 5 // # instance of weekday to start calendar on (5th Saturday for example)
        VAR __Base = CALENDAR(DATE(__StartYear,1,1),DATE(__StartYear,12,31))
        VAR __StartDate = 
            MAXX(
                FILTER(
                    ADDCOLUMNS(
                        __Base,
                        "WeekNum",COUNTROWS(FILTER(__Base,[Date]<=EARLIER([Date]) && WEEKDAY([Date],16) = __StartDay))
                    ),
                    [WeekNum]=__StartWeek && WEEKDAY([Date],16)=__StartDay
                ),
                [Date]
            )
        VAR __CalendarBase = CALENDAR(__StartDate,__StartDate + 52 * __NumYears * 7 - 1)
        VAR __Calendar = 
            ADDCOLUMNS(
                ADDCOLUMNS(
                    ADDCOLUMNS(
                        ADDCOLUMNS(
                            __CalendarBase,
                            "Year",ROUNDUP(([Date]-__StartDate+1)*1./ (52*7),0)-1+__StartYear,
                            "DAYOFWK#",MOD(([Date] - __StartDate),7)+1,
                            "SEQWK#",COUNTROWS(FILTER(__CalendarBase,[Date]<=EARLIER([Date]) && WEEKDAY([Date],16) = __StartDay)),
                            "DAY#YEAR",MOD(([Date]-__StartDate)*1.,(52*7))+1,
                            "DAY",DAY([Date])
                        ),
                        "WK#",ROUNDUP([DAY#YEAR]/7,0),
                        "QWK#",MOD([SEQWK#]-1,13)+1,
                        "Q",ROUNDUP([DAY#YEAR]/91,0)
                    ),
                    "Month",SWITCH(TRUE(),
                                [Q]=1 && [QWK#]<=4,1,
                                [Q]=1 && [QWK#]<=8,2,
                                [Q]=1,3,
                                [Q]=2 && [QWK#]<=4,4,
                                [Q]=2 && [QWK#]<=8,5,
                                [Q]=2,6,
                                [Q]=3 && [QWK#]<=4,7,
                                [Q]=3 && [QWK#]<=8,8,
                                [Q]=3,9,
                                [Q]=4 && [QWK#]<=4,10,
                                [Q]=4 && [QWK#]<=8,11,
                                [Q]=4,12
                            )   
                ),
                "MonthName",
                    SWITCH([Month],
                        1,"February",
                        2,"March",
                        3,"April",
                        4,"May",
                        5,"June",
                        6,"July",
                        7,"August",
                        8,"September",
                        9,"October",
                        10,"November",
                        11,"December",
                        12,"January"
                    )
            )
    RETURN
        __Calendar

     

    eyJrIjoiOTE4YTNmOWUtNTBjOS00ZjM3LWEzZjEtMTU3OTE2YjM5ZmFjIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ 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...
    CustomCalendar.pbix
    Labels:
    • Labels:
    • Financial
    • Other
    • Time Intelligence
    Message 1 of 2
    3,754 Views
    2
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    ericet
    ericet Helper I
    Helper I
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎01-16-2022 07:12 PM

    Hi Greg,

     

    Thank you for this. I'm really interested in making it work.

    I'm having trouble in fact, I can't figure it out. I need the calendar to start on Aug 30, 2021

    but I can't figure out what to do to make it start Aug 30, 2021

    Can you point me in the right direction ? 

    Thanks in advance

    Eric (Montreal, Canada)

     

    Message 2 of 2
    2,509 Views
    0
    Reply

    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
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices