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
    • Office 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
    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
    • Date Format Showdown! United States vs. The World

    Date Format Showdown! United States vs. The World

    09-03-2021 11:01 AM

    Super User Greg_Deckler
    Super User
    566 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
    • Email to a Friend
    • Report Inappropriate Content

    Date Format Showdown! United States vs. The World

    ‎09-03-2021 11:01 AM

    Answering questions on the forums sometimes leads to copying data in date formats that are not in United States date formatting. Now, normally I solve this in Power Query doing a split and then a recombination of values to get a United States date format. But, thought it would be interesting to have a DAX solution as well.

    TheWorldToUS = 
        VAR __Separator = "/"
        VAR __Date = MAX([TheWorld])
        VAR __Sep1 = SEARCH(__Separator,__Date,,1)
        VAR __Sep2 = SEARCH(__Separator,__Date,__Sep1+1,1)
        VAR __Day = LEFT(__Date,__Sep1 - 1)
        VAR __Month = MID(__Date,__Sep1+1,__Sep2 - __Sep1 - 1)
        VAR __Year = RIGHT(__Date,LEN(__Date) - __Sep2)
        VAR __YearFinal = IF(LEN(__Year&"")=2,__Year+2000,__Year)
    RETURN
        DATE(__YearFinal,__Month,__Day)

    There is also this variant:

    TheWorldToUS 2 = 
        VAR __Separator = "/"
        VAR __Date = MAX([TheWorld])
        VAR __DateText = SUBSTITUTE(__Date,__Separator,"|")
        VAR __Table = 
            ADDCOLUMNS(
                GENERATESERIES(1,3,1),
                "__DayPart",PATHITEM(__DateText,[Value],TEXT)
            )
        VAR __Day = MAXX(FILTER(__Table,[Value]=1),[__DayPart])
        VAR __Month = MAXX(FILTER(__Table,[Value]=2),[__DayPart])
        VAR __Year = MAXX(FILTER(__Table,[Value]=3),[__DayPart])
        VAR __YearFinal = IF(LEN(__Year&"")=2,__Year+2000,__Year)
    RETURN
        DATE(__YearFinal,__Month,__Day)

    The PBIX contains a column version as well as a USToTheWorld version which really just flips the Day and Month calculations.

    eyJrIjoiNzhhMDAyYTYtM2IyMS00ZjY5LTgwOGYtZTViZjFiN2I1ZGFiIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ me in replies or I'll lose your thread!!!
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Learn Power BI 2nd Edition
    DateFormatShowdown.pbix
    Labels:
    • Labels:
    • Other
    • Time Intelligence
    Message 1 of 1
    566 Views
    0
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • 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

    © 2022 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks