Power BI: let user pick chart x- and y-axis - 1 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
An innovative way to use the DAX TREATAS() - inspired by an article by Kasper de Jonge. Link to his article is at end of this article - also links to the pbix shown in screenshot above and to a live, interactive version. The user can choose what to show on the x-axis of the chart with the slicer on the left. The user can choose what to show on the y-axis with the slicer on the right. Data is from Adventure Works if you want to emulate (or use my pbix). Make sure that Calendar Year in DimDate is set to type text. Next a lot of DAX (impossible to format well in LinkedIn) - the two slicers are DAX tables, quantity is the same as sales:
MEASURE SLICER = UNION(ROW("Measure", "Quantity"), ROW("Measure", "Sales"))
AXIS SLICER = UNION(UNION(
CROSSJOIN(ROW("Axis", "Country"), VALUES(DimGeography[EnglishCountryRegionName])),
CROSSJOIN(ROW("Axis", "Product Category"), ALLNOBLANKROW(DimProductCategory[EnglishProductCategoryName]))
),
CROSSJOIN(ROW("Axis", "Year"), VALUES(DimDate[CalendarYear])))
Revenue = SUM(FactInternetSales[SalesAmount])
Sales =
SWITCH(
SELECTEDVALUE('AXIS SLICER'[Axis]),
"Country", CALCULATE([Revenue], TREATAS(VALUES('AXIS SLICER'[Attribute]), DimGeography[EnglishCountryRegionName])),
"Product Category", CALCULATE([Revenue], TREATAS(VALUES('AXIS SLICER'[Attribute]), DimProductCategory[EnglishProductCategoryName])),
"Year", CALCULATE([Revenue], TREATAS(VALUES('AXIS SLICER'[Attribute]),DimDate[CalendarYear])
))
Value =
SWITCH(
SELECTEDVALUE('MEASURE SLICER'[Measure]),
"Quantity", [Quantity],
"Sales", [Sales])
Links
Original Kasper de Jonge article
live, interactive version in PowerBI.com
Good Work, Could you please share the PBIX file again as the current link doesn't accessible ?
HAVELSAN Strateji Tak?m Lideri | Yar? Zamanl? ??retim üyesi - OST?M Teknik üniversitesi / ?ankaya üniversitesi | Stratejist | Maliyeci | Reklamc? | Y?netim Bili?im Sistemleri Uzman? | Gazeteci | Problem ??zücü
6 年You are the one. Wow
Consulente Business Intelligence @Altitudo || Microsoft Certified: Power BI Data Analyst Associate
7 年Thanks for sharing and inspiring, well done Art Tennick!
Save ??????by automating your semantic model build
7 年Love your work. Thanks for sharing and inspiring.