Power BI获得2周的当日价值 [英] Power BI getting 2 week back same day value
本文介绍了Power BI获得2周的当日价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Power BI中创建一个度量,该度量将始终提供同一工作日的2周前的销售额值。
I need to create a measure in Power BI which will always provide the value of sales amount 2 weeks back for the same weekday.
e.g Today = Tuesday 27-Sep-2016 so I need value for Tuesday 13-Sep-2016
表很简单,具有以下结构
The Table is simple with following structure
Date | SalesAmount
-----------------------------
01-Sep-2016 | 500
02-Sep-2016 | 450
03-Sep-2016 | 650
推荐答案
您可以使用 DATEADD ()
函数来计算每个日期之前的14天。使用下面的代码创建一个度量。
You can use DATEADD()
function to compute the 14 days before each date. Create a measure using the below code.
SalesTwoWeeksAgo =
CALCULATE (
SUM ( 'Table'[SalesAmount] ),
FILTER (
ALL ( 'Table' ),
COUNTROWS (
FILTER (
'Table',
EARLIER ( 'Table'[Date] ) = DATEADD ( 'Table'[Date], -14, DAY )
)
)
)
)
在以前的DAX表达式起作用的同时,我将创建一个计算列,该列比关于性能的度量方法更好。
While the previous DAX expression works, I'd create a calculated column which is better than the measure approach regarding to performance.
让我知道是否有帮助。
这篇关于Power BI获得2周的当日价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文