PowerBI DAX - Showing value for one category when another is selected

83 views Asked by At

I think I have a basic DAX filter problem that I am stuck with.

I have the following Sales fact table, where PeriodID is always 2:

Date Value Prod PeriodID
2022 10.00 Table 2
2021 10.00 Table 2
2021 10.00 Chair 2

It is joined to the following Period dimension table:

PeriodID Description
1 Opening
2 Closing

In the Matrix visualization, I am hoping to achieve this:

Opening (PeriodID = 1, 2021) Closing (PeriodID = 2, 2022)
Table 10.00 10.00
Chair 10.00 0.00

Since there is no PeriodID = 1 in the fact table, I try to achieve this with a measure for If PeriodID = 1, show PeriodID = 2 for 2021

However, Opening does not show up at all.

Closing (PeriodID = 2, 2022)
Table 10.00

Current Result

Following is my formula:

Sales_Total = 

VAR Calculate_Opening = 
CALCULATE(
    SUM(Sales[Value]),
    REMOVEFILTERS(Sales[PeriodID]),
    REMOVEFILTERS(Sales[Date]),
    FILTER(
        Sales,
        Sales[PeriodID] = 1
          &&Sales[Date] = SELECTEDVALUE(Sales[Date])-1
    )
)

VAR Results =
SWITCH(SELECTEDVALUE(Period[PeriodID]),
        1, Calculate_Opening,
        SUM(Sales[Value])
)

Return Results

I tried working around different filter functions to no avail, and I am not sure how to proceed debugging this. Any help is really appreciated. Thank you.

0

There are 0 answers