DAX - 高级产品 Grouping/Segmentation 问题

DAX - Advanced Product Grouping/Segmentation Question

我使用 AdventureWorksDW 数据库创建了一个 SSAS 表格模型。

我使用下面的 post 来帮助我构建报告。

https://blog.gbrueckl.at/2014/02/applied-basket-analysis-in-power-pivot-using-dax/

Sold in same Order:=
CALCULATE (
COUNTROWS ( 'Internet Sales' ),
CALCULATETABLE ( 
SUMMARIZE ( 
'Internet Sales',
'Internet Sales'[SalesOrderNumber]
),
ALL ( 'Product' ) ,
USERELATIONSHIP( 'Internet Sales'[ProductKey],FilteredProduct[ProductKey])
)
)

我已经验证公式的结果是正确的。有 1,381 个 Touring Tire Tube 的订单已售出,并显示有多少订单与其他商品一​​起售出(例如,1,381 个订单中的 170 个还包括产品密钥 214 - Sport-100 头盔,红色)。

这是我遇到问题的地方。我想通过显示有多少订单只包含我筛选的商品与与其他产品一起销售的订单来总结我的数据。这必须是动态的,因为用户可以 select 任何产品...最终结果应如下所示:

我是 DAX 新手,为此苦苦挣扎了几个小时。感谢您的帮助。

这是 table 关系:

此 DAX 应该适用于我博客中的示例数据集:

Orders with only the filtered products = 
--VAR vFilteredProducts = VALUES('Filtered Product'[ProductKey])
VAR vFilteredProducts = FILTER('Filtered Product', [ProductKey] = 530 || [ProductKey] = 541)
VAR vCountFilteredProducts = COUNTROWS(vFilteredProducts)
VAR vSales = CALCULATETABLE('Internet Sales',  -- get the Sales for the filtered Products
    vFilteredProducts,
    USERELATIONSHIP('Filtered Product'[ProductKey], 'Internet Sales'[ProductKey]), 
    ALL('Product'))
VAR vOrders = SUMMARIZE( -- Summarize the filtered product sales by Sales Order Number
    vSales, 
    [Sales Order Number],
    -- calucate the distinct filtered products in the filtered orders
    "CountFilteredProductsInOrder", CALCULATE(DISTINCTCOUNT('Internet Sales'[ProductKey])),
    -- calculate the all distinct products for the filtered orders 
    "CountTotalProductsInOrder", CALCULATE(DISTINCTCOUNT('Internet Sales'[ProductKey]), 
                ALLEXCEPT('Internet Sales', 'Internet Sales'[Sales Order Number]))
    )
RETURN COUNTROWS(
    FILTER(
        vOrders, 
        -- the total product count has to match the filtered product count --> no other products except filtered ones in order
        [CountFilteredProductsInOrder] = [CountTotalProductsInOrder]
    )
)

要获取除过滤后的产品外还销售其他产品的订单,请将最后一个 FILTER() 从 '=' 更改为 '<'