Power BI: families, creating and splitting apart - 5 of a series of 5 on the DAX TREATAS() function
more on TREATAS()

Power BI: families, creating and splitting apart - 5 of a series of 5 on the DAX TREATAS() function

Last in a series of five. Uses a DAX table and the magic TREATAS() function. To understand, please download the pbix and look at my previous four articles - all five articles show different and useful ways of working with DAX tables and TREATAS(). This example shows how to create a family (a world region and its countries) and separate from other families with a gap in charts and tables (tempted to call it Gap Analysis!). Based on Adventure Works DW, so you can experiment. All the links are next, some of the DAX after that:

pbix

article 1

article 2

article 3

article 4

LOCATION = FILTER(

UNION(

ADDCOLUMNS(SUMMARIZE(SELECTCOLUMNS(DimGeography, "Dimension", "Location", "Attribute", "Country", "Member", DimGeography[EnglishCountryRegionName], "World region", RELATED(DimSalesTerritory[SalesTerritoryGroup])), [Dimension], [Attribute], [Member], [World region]),

"Sort", [World region] & [Member]),

ADDCOLUMNS(SUMMARIZE(SELECTCOLUMNS(DimGeography, "Dimension", "Location", "Attribute", "World region", "Member", RELATED(DimSalesTerritory[SalesTerritoryGroup]),

"World region", ""), [Dimension], [Attribute], [Member], [World region]),

"Sort", [World region] & [Member]),

ADDCOLUMNS(SUMMARIZE(SELECTCOLUMNS(DimGeography, "Dimension", "Location", "Attribute", "Country", "Member",

REPT(" ", RANKX(DimSalesTerritory, DimSalesTerritory[SalesTerritoryGroup], RELATED(DimSalesTerritory[SalesTerritoryGroup]))), "World region",

RELATED(DimSalesTerritory[SalesTerritoryGroup])), [Dimension], [Attribute], [Member], [World region]), "Sort", [World region] & "zzz")

)

, [Sort] <> TOPN(1, VALUES(DimSalesTerritory[SalesTerritoryGroup]), DimSalesTerritory[SalesTerritoryGroup]) & "zzz"

)

Revenue = SUM(FactInternetSales[SalesAmount])

Revenue1 =

SWITCH(

   SELECTEDVALUE(LOCATION[Attribute]),

       "Country", CALCULATE([Revenue], TREATAS(VALUES(LOCATION[Member]), DimGeography[EnglishCountryRegionName])),

       "World region", CALCULATE([Revenue], TREATAS(VALUES(LOCATION[Member]), DimSalesTerritory[SalesTerritoryGroup])),

       [Revenue]

   )


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

Art Tennick的更多文章

社区洞察

其他会员也浏览了