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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
bao_nguyen
Frequent Visitor

Date Filter in Measure not working properly

Hello,

 

I have a table with columns Date and Failure Mode. I wrote a measure to calculate the passing rate in the last 30 days.

 

30 Day Yield =
VAR __pass = COUNTROWS(
    FILTER(
        'tbl',
        'tbl'[Failure Mode] == "PASS" &&
        'tbl[Date] >= TODAY()-30
    )
)

 

VAR __fail = COUNTROWS(
    FILTER(
        'tbl',
        not 'tbl'[Failure Mode] == BLANK() &&
        not 'tbl'[Failure Mode] == "PASS" &&
        'tbl[Date] >= TODAY()-30
    )
)
RETURN ROUND(IF(ISBLANK(DIVIDE(__pass,__pass+__fail)*100),0,DIVIDE(__pass,__pass+__fail)*100),0)
 
This returns the correct value but for the whole table instead of just 30 days. What interesting is when I add a slicer for relative date, it returns what I expected.
 
Please help!
 
Thanks!
3 REPLIES 3
v-huijiey-msft
Community Support
Community Support

Hi @bao_nguyen ,

 

Thanks for the reply from Wilson_ .

 

When you add a slicer for a relative date, it changes the filter context of the entire report page or visual, which is why you see the expected results when applying a slicer.

 

For more information on how filter context works see:

Filter context in DAX - SQLBI

 

If you want to implement your needs through DAX syntax, please provide me with the pbix file. Remember not to log in to your account on Power BI Desktop when uploading the pbix file.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hi Yang,

 

Thanks for the info. I am slowly reading through the link you provided. 

For now, I was able to get it to work by adding a date filter to the visual (card) but definitely not ideal.

I can't share my pbix file due to company policy but I can share a snippet of the data if that works?

 

Thanks!

Wilson_
Super User
Super User

Hi bao_nguyen,

 

Can you please share screenshots of your visual and/or model too?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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