Power BI: Year and Quarter on same axis - 3 of a series of 5 on the DAX TREATAS() function
Art Tennick
??3 US Patents in BI??technical editor 4 Packt Power BI books??author 20 computer books??Power BI??Analysis Services??Python/R in Power BI??Paginated??MDX DAX SQL Python R TMDL??ex-university SQL lecturer??35 years in BI
You can use this technique with any hierarchy, not just dates. No drilldown or bookmarks are required - it's all plain old DAX. Uses Adventure Works DW, so you can try this out easily. Essential background is in my two previous articles on this topic (the beauty and power of the DAX TREATAS() function). Here are the links to those articles and a link to the pbix. After the links is some DAX, but for a full understanding please read the other two articles as well.
First article in series
Second article in series
pbix download
A little DAX - a table and two measures:
X-AXIS =
SELECTCOLUMNS(UNION(
ADDCOLUMNS(VALUES(DimDate[CalendarYear]), "Quarter", 0, "Attribute", "Year", "Member", [CalendarYear]),
ADDCOLUMNS(CROSSJOIN(VALUES(DimDate[CalendarYear]), VALUES(DimDate[CalendarQuarter])), "Attribute", "Quarter", "Member", "Q" & [CalendarQuarter] & " " & [CalendarYear])
), "Dimension", "Date", "Attribute", [Attribute], "Member", [Member], "Year", [CalendarYear], "Quarter", [Quarter], "SortOrder", ([CalendarYear] * 10) + [Quarter])
Revenue = SUM(FactInternetSales[SalesAmount])
Sales =
SWITCH(
SELECTEDVALUE('X-AXIS'[Attribute]),
"Year", CALCULATE([Revenue], TREATAS(VALUES('X-AXIS'[Year]), DimDate[CalendarYear])),
"Quarter", CALCULATE([Revenue], TREATAS(SELECTCOLUMNS('X-AXIS', "Year", 'X-AXIS'[Year], "Quarter", 'X-AXIS'[Quarter]), DimDate[CalendarYear], DimDate[CalendarQuarter])
))
Consulente Business Intelligence @Altitudo || Microsoft Certified: Power BI Data Analyst Associate
7 年Another great job Art... Great!