1

I'm trying to generate a table using DAX in PowerBI to use as a date table, however in this case instead of the traditional list of days, I'm trying to generate a list of quarters- specifically the first date of a quarter.

I've tried using CALENDAR to generate days and then convert them to quarters, however I can't seem to find a way to transform the generated days into the first day of the quarter.

QTRMatrix = 
ADDCOLUMNS(
    STARTOFQUARTER(CALENDAR(MIN(Bookings[InvoiceMonth]),TODAY())),
    "Period", "Quarter"
)

This gives me an error stating:

"Function 'STARTOFQUARTER' cannot be used with columns added by ADDCOLUMNS or SUMMARIZE functions."

I've also tried this without ADDCOLUMNS which produces the same error as above.

Could someone please advise how I can achieve this?

1 Answer 1

1

The following DAX will produce a very useful calendar table:

Just create two measures for your period bounds:

Min Date :=
MIN( ‘Table’[Date] )

Max Date :=
MAX(‘Table’[Date] )

Then build your calendar based off of these dates:

Dates :=
VAR MinDate = [Min Date]
VAR MaxDate = [Max Date]

VAR BaseCalendar =
    CALENDAR ( MinDate, MaxDate )
RETURN
    GENERATE (
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR YearDate =
            YEAR ( BaseDate )
        VAR MonthNumber =
            MONTH ( BaseDate )
        VAR YrMonth =
            100 * YEAR ( BaseDate )
                + MONTH ( BaseDate )
        VAR Qtr =
            CONCATENATE ( "Q", CEILING ( MONTH ( BaseDate ) / 3, 1 ) )
        VAR YrMonthQtr =
            100 * YEAR ( BaseDate )
                + MONTH ( BaseDate )
                & CONCATENATE ( "Q", CEILING ( MONTH ( BaseDate ) / 3, 1 ) )
        VAR YrMonthQtrDay =
            100 * YEAR ( BaseDate )
                + MONTH ( BaseDate )
                & CONCATENATE ( "Q", CEILING ( MONTH ( BaseDate ) / 3, 1 ) )
                & DAY ( BaseDate )
        RETURN
            ROW (
                "Day", BaseDate,
                "Year", YearDate,
                "Month Number", MonthNumber,
                "Month", FORMAT ( BaseDate, "mmmm" ),
                "Year Month", FORMAT ( BaseDate, "mmm yy" ),
                "YrMonth", YrMonth,
                "Qtr", Qtr,
                "YrMonthQtr", YrMonthQtr,
                "YrMonthQtrday", YrMonthQtrDay
            )
    )

To get first day of quarter simply add a calculated column that flags the first day of each quarter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.