Reputation: 1590
While building a Calendar table with PowerQuery for a PowerPivot model in Excel 2013 I use its Date.QuarterOfYear function to get the number of the quarter.
Building the same thing in SSAS Tabular requires some workarounds. There's no equivalent DAX function to get number of the quarter from a DATE. Strangely, DAX has YEAR() and MONTH(), but no QUARTER().
Are nested IF
or SWITCH
statements really the only way in DAX to get the quarter number?
What is the reason for the absence such a simple and useful function? Am I overlooking the supreme wisdom of this decision?
Upvotes: 10
Views: 20741
Reputation: 1
Add column for get quarter :
Quarter = summary_bu_USD[Start Period].[Quarter]
Add column again and group year in column:
QuarterYear = YEAR(summary_bu_USD[Start Period])&" "&"Q"&RIGHT(summary_bu_USD[Quarter],1)
Upvotes: 0
Reputation: 1
You can also use this command:
=FORMAT(Date[Date],"q")
And combined them to create things like this
="Q." & FORMAT(Date[Date],"q") & " - "&Date[Year] = e.g. Q.1 - 2021
Upvotes: 0
Reputation:
DAX now has quarters! This is some date data:
And these are how you get the quarters and quarter numbers:
The results of these are below:
Upvotes: 5
Reputation: 738
I think they are assuming you'd create a date dimension in which your Quarter is pre-defined, including the Financial Year. I live in Australia where the Financial Year ends in June, and I've always pre defined the quarters as an added column to the table. IF you're using Power BI/Power Query you can add a query in the M code level (at the import stage).
Upvotes: 0
Reputation: 10978
No QUARTER() in DAX?
Yes, that is correct.
Really?
Yes, it's crazy and doesn't make any sense. Fortunately the workaround is just dividing the month by 3.
VAR quarterNumber = CEILING(MONTH([Date])/3,1)
Since DAX has multiple ways to round numbers, these will also work:
VAR quarterNumber = ISO.CEILING(MONTH([Date])/3,1)
VAR quarterNumber = ROUNDUP(MONTH([Date])/3,0)
Upvotes: 8