【问题标题】:DAX model invoice running balanceDAX 模型发票运行余额
【发布时间】:2015-10-02 07:54:18
【问题描述】:

我有一张发票表和一张付款表。发票表由发票编号、金额、发票日期、到期日组成。付款表由发票编号、金额、付款日期组成。发票表与到期日列上的日期表具有活动关系。付款表与发票 ID 列上的发票表具有活动关系。

我希望能够显示任意一天的发票余额。即,如果我在特定日期过滤报告或页面,我希望查看每张发票当天的实际余额。任何人都知道如何在不创建新表的情况下完成此操作并以编程方式在其中填写每日发票余额条目?

【问题讨论】:

    标签: powerpivot dax powerbi


    【解决方案1】:

    给你:

    InvoiceTotalAmount:=
    CALCULATE(
        SUM(Invoice[Amount])
        ,ALL(DimDate) // The active relationship between Invoice[ExpiryDate]
                      // and DimDate[Date] would cause this to only be valid
                      // on the expiry date - we don't want that.
    )
    
    PaymentTotalToDate:=
    CALCULATE(
        CALCULATE( // We'll manipulate the relationship in the inner
                   // CALCULATE() before modifying context based on it
            SUM(Payment[Amount])
            ,USERELATIONSHIP(Payment[Date], DimDate[Date])
       )
        ,FILTER( // Now that that we're looking at the right relationship to
                 // DimDate, we can alter the date range in context
            ALL(DimDate)
            ,DimDate[Date] <= MAX(DimDate[Date])
                // Here, we take all dates less than the latest date in
                // context in the pivot table - current date if 1 date in
                // context, else last of week, month, quarter, etc....
        )
    )
    
    InvoiceBalanceToDate:=[InvoiceTotalAmount] - [PaymentTotalToDate]
    

    如果您没有使用 Invoice[ExpiryDate] 和 DimDate[Date] 之间的活跃关系,我会将其标记为非活跃关系,并将 Payment[Date] 和 DimDate[Date] 之间的关系标记为活跃关系。然后,您可以省去 [InvoiceTotalAmount] 中的 CALCULATE() 和 ALL() 以及 [PaymentTotalToDate] 中的内部 CALCULATE()。

    我的模型图:

    【讨论】:

    【解决方案2】:

    您可能希望在日期表中创建一个度量,该度量使用 CALCULATETABLE 函数来计算当天发票的剩余余额。

    https://technet.microsoft.com/en-us/library/ee634760(v=sql.105).aspx

    【讨论】:

      猜你喜欢
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 2017-04-01
      • 1970-01-01
      相关资源
      最近更新 更多