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
Anonymous
Not applicable

Add DAX preceding month date filter to a measure

Hi all,

 

I've had a hunt for a solution, though starting from a pretty limied level of knowledge which doesn't help...

 

I have the following measure applied to my data, which gives me the accompanying Table. I got these values even though I've only specified "FAI", so suspect that's not helping things. The '0' is added to ensure the table adds a 0 when there's a null value

 

To Date = CALCULATE(COUNTAX('IR H&S Incident Register','IR H&S Incident Register'[Classification]="FAI"))+0
 
table.PNG
What I'd like to do now is apply a date filter to this, to calculate incidents which have occured in the preceding month. I know I could do it with a visual level filter, but not in the same visual.
 
Hope you can help!
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To use this measure should work.

To Date =
VAR this_month =
    FORMAT ( TODAY (), "mm-yyyy" )
RETURN
    CALCULATE (
        COUNTAX (
            'IR H&S Incident Register',
            'IR H&S Incident Register'[Classification] = "FAI"
        ),
        FILTER (
            'IR H&S Incident Register',
            FORMAT ( 'IR H&S Incident Register'[date], "mm-yyyy" ) = thsi_month
        )
    ) + 0
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To use this measure should work.

To Date =
VAR this_month =
    FORMAT ( TODAY (), "mm-yyyy" )
RETURN
    CALCULATE (
        COUNTAX (
            'IR H&S Incident Register',
            'IR H&S Incident Register'[Classification] = "FAI"
        ),
        FILTER (
            'IR H&S Incident Register',
            FORMAT ( 'IR H&S Incident Register'[date], "mm-yyyy" ) = thsi_month
        )
    ) + 0
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.