Power BI: Year and Quarter on same axis - 3 of a series of 5 on the DAX TREATAS() function

Power BI: Year and Quarter on same axis - 3 of a series of 5 on the DAX TREATAS() function

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])

       ))

Simone Schiavon

Consulente Business Intelligence @Altitudo || Microsoft Certified: Power BI Data Analyst Associate

7 年

Another great job Art... Great!

要查看或添加评论,请登录

Art Tennick的更多文章

社区洞察

其他会员也浏览了