Forum Discussion
How do I use a date filter for a measure?
- 4 years ago
Hi HamidBee.
I'm assuming that you have a date table in your data model and that it is marked appropriately. If so, this should be fairly easy with either the DATESBETWEEN or DATESINPERIOD functions. Pick a function and insert the appropriate start and end dates as parameters. Hope this helps!
Hi HamidBee.
I'm assuming that you have a date table in your data model and that it is marked appropriately. If so, this should be fairly easy with either the DATESBETWEEN or DATESINPERIOD functions. Pick a function and insert the appropriate start and end dates as parameters. Hope this helps!
- HamidBee4 years ago
Power Participant
Thank you, it worked like a charm. I haven't created a date table though I just used a date column from the same table. Here is an example code of what I used:
Count=CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Coumn]="Allowed"),(DATESBETWEEN('Table'[Date column],DATE(2020,01,01),DATE(2021,01,01))))
Correct me if I'm wrong but it seems the Filter function must come before the DATESBETWEEN function in the formula otherwise DAX gives an error. Do you know why this is?
Thanks in advance- littlemojopuppy4 years ago
Community Champion
Hi HamidBee. It's good practice to always have a date table in your data models.
Why the error...not really sure and without the pbix would be hard to tell. But I did put your formula through the DAX formatter from SQLBI and you have extra parentheses before DATESBETWEEN.
Count = CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', 'Table'[Coumn] = "Allowed" ), ( DATESBETWEEN ( 'Table'[Date column], DATE ( 2020, 01, 01 ), DATE ( 2021, 01, 01 ) ) ) )