Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Titatovenaar2
Helper III
Helper III

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

 

1 ACCEPTED SOLUTION
m3tr01d
Continued Contributor
Continued 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
)

View solution in original post

2 REPLIES 2
Titatovenaar2
Helper III
Helper III

Works perfectly, thanks!

m3tr01d
Continued Contributor
Continued 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
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.