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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SSBTexas
Regular Visitor

Filter Table based on measure not working correctly - Dates

I'm trying to determine why my date measure used to filter a table is not working.  

I have created a measure called PriorMonthStart.   Its value is calculated and is shown as 07/01/2021.   All set... looks good.  

SSBTexas_2-1629066261720.png

 

Then I am counting the number of rows for a date equal to greater than the PriorMonthStart in this dataset:

SSBTexas_0-1629066082669.png

MonHiresCount = CALCULATE(
COUNTROWS(EMP_HIRES),
FILTER(EMP_HIRES, EMP_HIRES[HIRE_DATE] >= [PriorMonthStart]))
 
The value of MonHiresCount = 9 whereas it should be 1.   
 
If I change the MonHiresCount Measure to: 
MonHiresCount = CALCULATE(
COUNTROWS(EMP_HIRES),
FILTER(EMP_HIRES, EMP_HIRES[HIRE_DATE] >= Date(YEAR([PriorMonthStart]),7,1)))   
I get the correct value of 1.  
 
If I try the MonHiresCount Measure to: 
MonHiresCount = CALCULATE(
COUNTROWS(EMP_HIRES),
FILTER(EMP_HIRES, EMP_HIRES[HIRE_DATE] >= Date(YEAR([PriorMonthStart]),MONTH([PriorMonthStart]),1)))   
It reverts back to being wrong again.  MonHiresCount = 9  
 
I even created another measure called Month-PriorMonth
SSBTexas_4-1629066736439.png
MonHiresCount = CALCULATE(
COUNTROWS(EMP_HIRES),
FILTER(EMP_HIRES, EMP_HIRES[HIRE_DATE] >= Date(YEAR([PriorMonthStart]),[Month-PriorMonth],1)))   and the result is still 9.  
 
It seems like it it somehow reverting the month value from 7 to 6.  
 
The kicker???   It's working correctly with last months file (no changes in format)
 
AND with this month's file it has no issues in being used for a different calculation and producing correct results.  
MonTermsCount = CALCULATE(
COUNTROWS(EMP_TERMS),
FILTER(EMP_TERMS,EMP_TERMS[TERM_DATE] >= [PriorMonthStart]))
 
Any ideas?  

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @SSBTexas ,

 

Not sure what is [DataThurMonth],is it a measure?Is it a fixed value?Will it cause a context problem?

Here I made a simple sample according to your data and using value of "today()" instead:

vkellymsft_1-1629252579931.png

 

PriorMonthStart = DATE(YEAR(TODAY()),MONTH(TODAY())-1,1)
MonHiresCount = CALCULATE(
COUNTROWS('Table'),
FILTER(ALL('Table'), 'Table'[Hire_Date] >= [PriorMonthStart]))

And you will see:

vkellymsft_0-1629252559721.png

 

Check my sample .pbix file attached for reference.

 

Best Regards,
Kelly

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

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @SSBTexas ,

 

Not sure what is [DataThurMonth],is it a measure?Is it a fixed value?Will it cause a context problem?

Here I made a simple sample according to your data and using value of "today()" instead:

vkellymsft_1-1629252579931.png

 

PriorMonthStart = DATE(YEAR(TODAY()),MONTH(TODAY())-1,1)
MonHiresCount = CALCULATE(
COUNTROWS('Table'),
FILTER(ALL('Table'), 'Table'[Hire_Date] >= [PriorMonthStart]))

And you will see:

vkellymsft_0-1629252559721.png

 

Check my sample .pbix file attached for reference.

 

Best Regards,
Kelly

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

Greg_Deckler
Super User
Super User

@SSBTexas The issue is likely related to your PriorMonthStart and is also likely a context issue. It's hard to really know though without sample data, etc. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.