Power BI getting 2 week back same day value

橙三吉。 提交于 2019-12-25 08:09:08

问题


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

回答1:


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 )
            )
        )
    )
)

While the previous DAX expression works, I'd create a calculated column which is better than the measure approach regarding to performance.

Let me know if this helps.



来源:https://stackoverflow.com/questions/39716057/power-bi-getting-2-week-back-same-day-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!