我有一张包含发票和付款表格的表格。发票表包括发票ID,金额,发票日期,到期日期。付款表包括发票ID,金额,付款日期。发票表与到期日期列上的日期表具有活动关系。付款表与发票ID列上的发票表具有活动关系。
我希望能够在任意一天显示发票余额。即如果我在特定日期过滤报告或页面,我希望在每天的发票上看到当天的平衡。任何人都知道如何在不创建新表的情况下完成此操作并以编程方式填写每日条目的发票余额?
答案 0 :(得分: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()。
答案 1 :(得分:0)
您可能希望在日期表中创建一个度量,该度量使用CALCULATETABLE函数计算当天发票的余额。
https://technet.microsoft.com/en-us/library/ee634760(v=sql.105).aspx