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
    • 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
    • COUPON

    COUPON

    05-10-2020 16:56 PM - last edited 05-10-2020 17:02 PM

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

    COUPON

    ‎05-10-2020 04:56 PM

    In my recent quest to create or catalog as many DAX equivalents for Excel functions, these were incredibly frustrating just simply becuase of the rampant lack of documentation. I mean, wow, one might call it useless I suppose but I consider the term useless far too positive of a description. I literally had to reverse engineer these things. 

     

    There are certain circumstances where my COUPDAYS does not match Excel's, there is a day or .5 or .25 days off when using a Basis of 3 but without some guidance as to what the flip Excel's functions are doing under the hood for an Actual/365; whatever that means, who knows what is going on. And that keen insight is certainly not coming from the garbage documentation.

     

    The PBIX includes measures for the following Excel functions:

    • COUPDAYS
    • COUPDAYSNC
    • COUPDAYBS
    • COUPNCD
    • COUPPCD
    • COUPNUM

    I am only posting here in the text a respresentative sample because they are all rather repetitive.

     

    COUPNCD = 
        VAR __Settlement = [Settlement]
        VAR __Maturity = [Maturity]
        VAR __Frequency = MAX('Table'[Frequency])
        VAR __Basis = MAX('Table'[Basis])
        VAR __Table = 
            ADDCOLUMNS(
                GENERATESERIES(0,4,1),
                "Date",
                    VAR __Months = (4 - [Value]) * (-3)
                    VAR __Date = EOMONTH(__Maturity,__Months)
                    RETURN DATE(YEAR(__Date),MONTH(__Date),DAY(__Maturity))
            )
    RETURN
        SWITCH(__Frequency,
            1,MINX(FILTER(__Table,([Value] = 0 || [Value] = 4) && [Date] > __Settlement),[Date]),
            2,MINX(FILTER(__Table,([Value] = 0 || [Value] = 2 || [Value] = 4) && [Date] > __Settlement),[Date]),
            4,MINX(FILTER(__Table,[Date] > __Settlement),[Date]),
            BLANK()
        )
    
    COUPDAYSNC = 
        VAR __Settlement = [Settlement]
        VAR __Maturity = [Maturity]
        VAR __Frequency = MAX('Table'[Frequency])
        VAR __Basis = MAX('Table'[Basis])
        VAR __COUPNCD = [COUPNCD]
    RETURN
        SWITCH(TRUE(),
            __Basis = 1 || __Basis = 2 || __Basis = 3, ( __COUPNCD - __Settlement ) * 1.,
            __Basis = 0 || __Basis = 4 || ISBLANK(__Basis),
                VAR __Date1 = __Settlement
                VAR __Date2 = __COUPNCD
                VAR __CalendarBase =
                    FILTER(
                        CALENDAR(__Date1,__Date2),
                        DAY([Date]) <= 30
                    )
                VAR __FebCal =
                    SUMMARIZE(
                        ADDCOLUMNS(
                            FILTER(
                                __CalendarBase,
                                MONTH([Date]) = 2 && (DAY([Date]) = 28 || DAY([Date]) = 29) ||
                                    MONTH([Date]) = 3 && DAY([Date]) = 1
                            ),
                            "Year",YEAR([Date])
                        ),
                        [Year],
                        "FebExtraDays",
                            VAR __Year = [Year]
                            VAR __Div4 = IF(MOD(__Year,4)=0,TRUE(),FALSE())
                            VAR __Div100 = IF(MOD(__Year,100)=0,TRUE(),FALSE())
                            VAR __Div400 = IF(MOD(__Year,400)=0,TRUE(),FALSE())
                            VAR __IsLeapYear = IF(__Div4 && NOT(__Div100),TRUE(),IF(__Div4 && __Div100 && __Div400,TRUE(),FALSE()))
                        RETURN IF(__IsLeapYear,1,2)
                    )
                VAR __Adjustment = IF(DAY(__Date1)>30 || DAY(__Date2)>30,0,-1)                
            RETURN
                COUNTROWS(__CalendarBase) + SUMX(__FebCal,[FebExtraDays]) + __Adjustment,
            BLANK()
        )

     

    NOTE: Creating these functions helped me identify a bug in DAYS360 so I updated that in the Quick Measures Gallery. Also, and I just have to rant on this because these took me pretty much all day to figure out when it should have been like an hour because, let's face it, these things are pretty brainless once you reverse engineer what they are doing, but I mean, not even the naming convention is consistent. You have COUPNCD (coupon next coupon date), COUPPCD (coupon previous coupon date), COUPDAYS, COUPDAYSNC and then..drum roll...COUPDAYBS, I mean, shouldn't it be COUPDAYSPC for; oh I don't know, freaking consistency sake if nothing else? Come on man...that's just lazy. I mean, it's really kinda BS or a developer TOTALLY slipped that one by management.

     

    And, honestly, the Excel functions seems buggy to me because, for example, using the maturity and settlement and a Frequency of 1 and Basis of 2 Excel gives back 294 for COUPDAYSNC and 71 for COUPDAYBS but then COUPDAYS maxes out at 360. Well, using the 360 calculation for COUPDAYSNC and COUPDAYBS gives back 290 and 70 respectively. So... Anyway, it's all a trainwreck in my opinion.

    eyJrIjoiODg3MmYwYjctZTk4ZC00YzY4LWFhMzItYjMzMDM3N2I1YzRlIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ 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...
    Preview file
    47 KB
    COUPON.pbix
    Labels:
    • Labels:
    • Financial
    Message 1 of 1
    759 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
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices