如何汇总同一张发票中的项目类型以在 DAX 中查找百分比

How to sum up item types within the same invoice to find percentages in DAX

在一张发票中,有多个项目,包括一个折扣项目。我如何找到整张发票的折扣百分比,然后用它来计算每件商品的调整后金额?

我可以使用 summarize 和 sumx 找到每张发票的百分比,但我无法将其获取到项目级别。

这是我目前的事实table:

Invoice Type        Item            Dollars
11111   Shipment    pancake         50
11111   Shipment    waffle          200
11111   Discount    discount item   20
11111   Discount    discount item   30

这就是我要创建的内容:

item    dollars discount %  adjusted dollars
pancake 50      0.2         40
waffle  200     0.2         160

以下是我要实现的步骤:

  1. 将每种类型的美元相加
    • 出货量 = 250
    • 折扣 = 50
  2. 查找折扣百分比
    • 折扣/运费 = 20%
  3. 使用该折扣百分比来调整每件商品的美元金额。
    • 调整后的煎饼 = 50 * (1 - 0.2) = 40
    • 调整后的华夫饼 = 200 * (1 - 0.2) = 160
  4. 将这些调整后的美元加起来。

我的想法是,我可以将项目或发票放在数据透视表 table 的列上,并获得调整后的美元金额。我可以只为发票做这件事,但我不知道如何在项目级别做。

如有任何帮助,我们将不胜感激。

增加以下措施

发货金额:

Shipment Amount = 
    CALCULATE ( 
        SUM ( FactTable[Dollars] ),
        FactTable[Type] = "Shipment"
    )

发票折扣%:

Invoice Discount % = 
VAR InvoiceShipment = 
    CALCULATE ( 
        SUM ( FactTable[Dollars] ),
        FILTER ( 
            ALLEXCEPT ( FactTable, FactTable[Invoice] ), 
            FactTable[Type] = "Shipment"
        )
    )
VAR InvoiceDiscount = 
    CALCULATE ( 
        SUM ( FactTable[Dollars] ),
        FILTER ( 
            ALLEXCEPT ( FactTable, FactTable[Invoice] ), 
            FactTable[Type] = "Discount"
        )
    )
RETURN
    DIVIDE ( 
        InvoiceDiscount, 
        InvoiceShipment, 
        BLANK()
    )

调整后的金额:

Adjusted Amount = 
    SUMX ( 
        FactTable,
        [Shipment Amount] * ( 1 - [Invoice Discount %] )
    )

现在您可以根据需要在可视化中使用它们。

参见 https://pwrbi.com/so_55602327/ 例如 PBIX 文件