Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I am trying to create a measure that iterates through each date in my date table and if the date is between a range, it will give it a value of 1, and if the date is not in that range, it gives it a 0. The use case for this is so that I can have a slicer that allows users to select a single month of the year, and give them the data from the beginning of the year to the end of the month selected. I am doing my slicer this way as there are some visuals that will need to show data in the way described earlier, from beginning of the year to end of selected month, and there are other visuals that will only show data for that single selected month.
My process for this currently is that I have a Measure that will return the selected month for the slicer:
See if this works for you. I have the Date table as follows:
and the table for the slicer is
Now you can use this measure to flag the dates:
Filter Dates =
VAR _MaxMonth =
SELECTEDVALUE ( 'Month Slicer'[MonthNum] ) + 1 //No need for the Switch expression since we already have the month number in the table
VAR _StartDate =
DATE ( YEAR ( TODAY () ), 1, 1 )
VAR _EndDate =
DATE ( YEAR ( TODAY () ), _MaxMonth, 1 ) //If you want the last date to be the selected month (instead of the first date of the following month), add - 1 to the _EndDate expression
RETURN
IF (
MAX ( 'Date Table'[Date] )
IN DATESBETWEEN ( 'Date Table'[Date], _StartDate, _EndDate ),
1
)
The problem you were having in the IF(DATESBETWEEN()) Measure is that the DATESBETWEEN function returns a table of values. So you need to check if the MAX(Date Table[Date]) is listed (IN function) in the table created by DATESBETWEEN. Make sense?
EDIT: Just thought it worth pointing out that even if you select December, which will return a month value of 13 - which doesn't exist of course - the DATE function will automagically change the year to year +1 and the month from December to January
Sample PBIX file attached
Proud to be a Super User!
Paul on Linkedin.
@PaulDBrown I'm not sure what I am doing wrong but this is the result that I am getting:
As you can see, no matter which date I choose, the visual on the right stays the same. I copied and pasted your tables/measures to see if I could get it to work properly and it wouldn't work the same way that yours does. Here are screenshots from my attempt, and the only difference is that my measure is named "TEST Filter Dates" instead of "Filter Dates":
It's probably because your date field is type Date/Time (The DATE function will return a date, unless you format it as Date/Time).
Unless you have real Date/Time fields in the model, format the fields as Type DATE
Proud to be a Super User!
Paul on Linkedin.
@PaulDBrown I changed the data type of my date field to the same that is in your example and it still isn't changing based on the month selected.
can you check if there is a relationship between the tables? (There shouldn't be).
Otherwise, if this is a test file, can you post a link to the file in the cloud so I can download it?
Proud to be a Super User!
Paul on Linkedin.
@PaulDBrown There are no relationships between the tables that I created for this, and this is my actual working pbix file so I cannot share it in this thread I apologize.
There should be no relationship between the month slicer table and any other tables. Also, in my example, the date field in the visual is from the date table
Proud to be a Super User!
Paul on Linkedin.
Update: I have changed my final formula to:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
121 | |
79 | |
48 | |
37 | |
30 |
User | Count |
---|---|
191 | |
78 | |
71 | |
50 | |
42 |