Forum Discussion

MP-iCONN's avatar
MP-iCONN
Resolver I
4 years ago

Custom Accounting Calendar

I am trying to create a custom calendar table to match our companies accounting calendar.  I tried with a nested if statement to get the month names and that does work but when I add the custom month name column it will just sort the month name in alphabetical order, so I think there has to be a better way.

 

Here is the custom accounting calendar showing month ends:

 

 

Any help is greatly appreciated!

5 Replies

  • You have two problems goint on. First is the calendar itself. For that you may need to create a table in Excel that has things like [Calendar Month Name], [Accounting Month Name], [Accounting Month Number], etc. Maybe add [Last Day of Period] as well if you need it for calculations. Every Calendar Date from Feb. 29 through April 3 will have [Accounting Month Name] = March, and [Accounting Month Number] = 3, and [Last Day of Period] = 4/3/YYYY. Join this calendar table to your fact table on transaction date.

    Next, for the [Accounting Month Name] column, assign its Sort by Column to be [Accounting Month Number] (under the Column Tools menu, I think).

    Hope that helps.

  • Accelins's avatar
    Accelins
    Frequent Visitor

    I would create a data table in dax using the code below - 

     

    Date Table = 
    ADDCOLUMNS (
        CALENDARAUTO (),
        "Year", YEAR ( [Date] ),
        "Quarter", FORMAT ( [date], "\QTR q" ),
        "Month", MONTH ( [date] ),
        "Month Name", FORMAT ( [Date], "MMMM" ),
        "Day", DAY( [date]),
        "Month Name", FORMAT ( [Date], "MMMM DD" )
    )

     

     

    Then add in a calculated column with If statments to add a boolean for month end. like this (add in other months)

    is_month_end =
    IF (
        'Date Table'[Month & Day]
            IN {
            "January 30",
            "Febuary 27"
        },
        1,
        0
    )



    • Accelins's avatar
      Accelins
      Frequent Visitor

      you could go a step further and add boolean for each full account month.

      accounting_month =
      IF (
          'Date Table'[Month & Day] >= "January 01"
              && 'Date Table'[Month & Day] <= "January 30",
          1,
          IF (
              'Date Table'[Month & Day] >= "January 31"
                  && 'Date Table'[Month & Day] <= "Febuary 27",
              2,
              -1
          )
      )

       

      This way you can do somthing like

      Janaury 2022 Sales =
      CALCULATE (
          SUM ( 'Sales'[sales] ),
          CALCULATETABLE ( 'Date Table', [accounting_month] = 1 ),
          CALCULATETABLE ( 'Date Table'[year] = 2022 )
      )
  • Accelins The problem with big IF statements for things like this is that they are not extensible. If we had exactly 364 days in every year, then January 1 would fall on the same day of the week each year. Wouldn't that be boring? But we have 365 for three years, then 366 for leap year so the date of the first or last Sunday of the month will change every year. Your calculation, while it may work for THIS year, will need to be edited again for NEXT year. And if you EDIT it, then it breaks THIS year, so now you need to add additional logic about the year in the IF statements. 

    As a modeller, I prefer to push this type of business logic to the business, as rows in a table instead of embedded code. I want my model to survive from year to year if I am not around to continually edit it. 

    • Accelins's avatar
      Accelins
      Frequent Visitor

      yeah for sure in my code the assumption is that its these dates every year, hence no year was included in the calculated column, If the date change every year a table provided by the business is a better soultion.