基于断开连接的切片器的动态 X 轴日期范围

Dynamic X-Axis Date Range Based on Disconnected Slicer

我有一个问题需要帮助。我正在使用基于此 table

的断开连接的切片器
Time Frame := 
DATATABLE("ID", Integer, "Time Frame", string
, {
  {1, "3 Month"}
, {2, "6 Month"}
, {3, "9 Month"}
, {4, "12 Month"}
})

看起来像这样:

使用一些 DAX 指标:

Sum Of Paid := sum(Data[Paid])

Sum Of Paid 3 Month Period :=
CALCULATE (
    [Sum Of Paid],
    DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -3, MONTH )
)

Sum Of Paid 6 Month Period :=
CALCULATE (
    [Sum Of Paid],
    DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -6, MONTH )
)

Sum Of Paid 9 Month Period :=
CALCULATE (
    [Sum Of Paid],
    DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -9, MONTH )
)

Sum Of Paid 12 Month Period :=
CALCULATE (
    [Sum Of Paid],
    DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -12, MONTH )
)

Slicer - Paid Per Period :=
VAR selection =
    IF (
        HASONEVALUE ( 'Time Frame'[Time Frame] ),
        VALUES ( 'Time Frame'[Time Frame] ),
        "All"
    )
VAR ThreeMonth = [Sum of Paid 3 Month Period]
VAR SixMonth = [Sum of Paid 6 Month Period]
VAR NineMonth = [Sum of Paid 9 Month Period]
VAR TwelveMonth = [Sum of Paid 12 Month Period]
RETURN
    SWITCH (
        TRUE (),
        selection = "3 Month", ThreeMonth,
        selection = "6 Month", SixMonth,
        selection = "9 Month", NineMonth,
        selection = "12 Month", TwelveMonth,
        TwelveMonth
    )

我可以模拟切片器并根据用户选择显示 3、6、9 和 12 个月的汇总。这些在卡片、等值线和几乎所有我需要它们的地方都工作得很好。我的问题是尝试创建在 x 轴上具有日期范围的折线图、条形图等。我一辈子都想不出如何复制 DAX 度量中引用的周期来动态设置 x 轴。

我尝试了一些看起来应该有效但无效的方法:

3 Month Period :=
CALCULATE (
    VALUES(Data[Date]),
    DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -3, MONTH )
)

感谢任何帮助。

谢谢

你可能想试试这个:

3 Month Period :=
CALCULATE (
    [Sum Of Paid],
    KEEPFILTERS (
        DATESINPERIOD (
            Data[Date],
            CALCULATE (
                MAX ( Data[Date] ),
                ALLSELECTED ()
            ),
            -3,
            MONTH
        )
    )
)