Microsoft Power BI Cookbook
上QQ阅读APP看书,第一时间看更新

Accessories but not bike customers

  1. Create a DAX measure which returns the count of customers who've purchased an accessory but not a bike:
Count of Accessory But Not Bike Customers = 
VAR BikeCustomers =
SUMMARIZE(CALCULATETABLE('Internet Sales','Product'[Product Category] = "Bikes"),
Customer[Customer Alternate Key])
VAR AccessoryCustomers =
SUMMARIZE(CALCULATETABLE('Internet Sales','Product'[Product Category] = "Accessories"),
Customer[Customer Alternate Key])
RETURN
CALCULATE(DISTINCTCOUNT(Customer[Customer Alternate Key]),EXCEPT(AccessoryCustomers,BikeCustomers))
  • Variables are used to store the distinct customer keys associated with the two product categories.
  • SUMMARIZE() groups the customer key values and EXCEPT() performs the set-based operation.
  1. Create card and table visuals in a Power BI Report to visualize the new measure:
Visualization of EXCEPT() DAX Measure: Accessory Customers excluding Bike Customers
  • The measure can be visualized across dimensions such as filtering for one or two calendar years