1

我有一个 Date 表和一个 FactSales 表,它们的关系是 Date[date] 和 FactSales[Date]。我有一个衡量销售额的方法,例如总销售额 = SUM(FactSales[sales])。我有一张名为 Relation 的表。

_______________________________________________________________________
Match                    | TypeID | Type           | No  |Datepartname |
________________________________________________________________________
DEFAULT - Year on Year   | 1      |Userelationship | NA  | NA          |
Previous 1 Week          | 3      | Dateadd        | 1   | Week        |
Previous 2 Week          | 3      | Dateadd        | 2   | Week        |
Previous 3 Week          | 3      | Dateadd        | 3   | Week        |
Previous 12 Week         | 3      | Dateadd        | 12  | Week        |
------------------------------------------------------------------------ 

此 Relation[Match] 列将用作切片器,该切片器将过滤日期表以根据所选内容获取总销售额。

我正在努力通过使用下面的 DAX 来完成这项工作:首先我需要使用变量 _maxDate 来识别当前日期

measure = 
Var _maxDate = CALCULATE ( MAX ( Date[Dates] ), ALLSELECTED ( Date ) )   --- current's date
var _selection = SELECTEDVALUE(Relation[Match] )
RETURN
SWITCH(TRUE(),
        _selection = "DEFAULT - Year on Year", "DEFAULT - Year on Year",
        _selection = "Previous 1 Week", DATEADD(Date[Dates],-7,DAY),
        _selection = "Previous 2 Week”, DATEADD(Date[Dates],-14,DAY),
        _selection = "Previous 3 Week", DATEADD(Date[Dates],-21,DAY),
        _selection = "Previous 12 Week", DATEADD(Date[Dates],-84,DAY),
        BLANK()
)

我的 Dax 返回错误。

预期结果:

Whenever, Previous 1 week is selected on the slicer, it should return the previous week date and when Previous 2 week is selected, it should return 2 weeks ago date and so on. 如果实现了这一点,则应根据切片器上选择的内容自动计算度量。

4

0 回答 0