Forum Discussion
DAX Filter Context: Show Current Month Value while ignoring RELATED Calendar selection
Hi guys,
The idea I want to achieve is pretty simple: I want to show the total Stock (based on a SUM of a column of table 'FACT Inventory') of the current month (2021-07), while it ignores any period selected from the 'DIM Calendar's period selection, which is related 1:* one directional to 'FACT Inventory'.
I thought about doing this the following way:
- First remove the entire 'DIM Calendar' filter context, by using ALL('DIM Calendar')
- Then after that, set it dynamically to the latest month, using the following DAX:
CALCULATE(
[Closing Stock],
ALL('DIM Calendar'[Date]),
FILTER(
'Fact Inventory',
RELATED('DIM Calendar'[YearMonth]) = FORMAT(TODAY(), "YYYY-MM")
)
)
The Closing Stock measure is really simple:
CALCULATE(
SUM('Fact Inventory'[Quantity]),
'Fact Inventory'[Source] = "OpeningStock"
)
Somehow this still reacts to a period that I select. If I select the entire 2021, I do see only a value at month 2021-07. However, If I select a period from 2021-01 until 2021-06, it won't show me the current month that is 2021-07.
Any ideas how to adapt the filter context in a way that it will show me the current month's value?
Kind regards,
Igor
Hello, you should probably use something like :
VAR _Today = FORMAT(TODAY(), "YYYY-MM") RETURN CALCULATE( [Closing Stock], ALL('DIM Calendar'[Date]), 'DIM Calendar'[YearMonth] = _Today )
2 Replies
- m3tr01dContinued Contributor
Hello, you should probably use something like :
VAR _Today = FORMAT(TODAY(), "YYYY-MM") RETURN CALCULATE( [Closing Stock], ALL('DIM Calendar'[Date]), 'DIM Calendar'[YearMonth] = _Today ) - Titatovenaar2Advocate II
Works perfectly, thanks!