I have 3 tables. Calendar, Sale and Parameter.
Parameter has values ranging from 1-24, which are the number on months I want to go back.
I am trying to filter a slicer which has dates from the calendar table, based on the month of the sales date.
I have taken the last sale date and then gotten the min and max dates in 2 different measures, using the parameter value.
Now I want to dynamically filter a slicer which has dates from the calendar table, with above mentioned min and max dates.
Last Sale Date is 17th May 2023.
Selected Parameter Value is 3.
Max Calendar Date will be 30th April 2023
Min Calendar Date will be 1st Feb 2023.
Last Sale Date is 12th Feb 2023.
Selected Parameter Value is 5.
Max Calendar Date will be 31st Jan 2023.
Min Calendar Date will be 1st Sep 2022.
Now I want to filter the slicer value to have dates between 1st Feb 2023 and 30th April 2023.
This will be dynamic based on the parameter values.
I have tried using the relative date slicer, but that works based on the current date of the system.
I also cannot use the sale date in the relative date slicer either, as it is a fact table.
Please let me know if you need any further information.
You need another measure like
Date is visible = IF ( SELECTEDVALUE ( 'Date'[Date] ) IN CALENDAR ( [Min date], [Max date] ), 1 )
and use that as a visual level filter on the slicer.
try creating a temporary table like
tmp table = ADDCOLUMNS ( VALUES ( 'Date'[date] ), "@step 1", [1 Step], "@step 2", [2 Step] )
and you can then use the data view to look for dates where either step 1 or step 2, or both, are blank.
The new table did not work as start date is 31-12-1899 and the end date is blank.
I think is cause of the parameters used in the measures, when using them in a table, there is no context.
I tried modifying your code to use DATESBETWEEN() instead of CALENDAR(), it is not giving an error, but its not working either.
Anything else that you can think of?
That's the problem. You need to make sure that when step 1 and step 2 are calculated inside the date visible measure they get the same filters as are being applied in your card visuals.
Thank you for staying with me so far and responding instantly!
Solved the Step 1 and Step 2 problem.
Here is the current position:
I used the REMOVEFILTERS()/ALL() function and removed the filters from the Calendar Date column, so that only the last date of sales is considered.
And I used the above mentioned Date Visible measure on the slicer.
A weird thing was happeneing, that when I am using, DATESBETWEEN() function it works, not completely but it works, but when I use the calendar function to get the dates in between the start and end dates, it gives me an error, that the start date cannot be more than the end date.
I wonder if the problems are to do with it being the date table we're trying to filter. Instead of using IN you could try
Date is visible = IF ( SELECTEDVALUE ( 'Date'[Date] ) >= [2 Step] && SELECTEDVALUE ( 'Date'[Date] ) <= [1 Step], 1, 0 )
Tried and still not working.
Sharing a sample file for you to play around it if you will.
I tried this technique as well, but didn't seem to work. Have a look at it.
Is Visible = VAR CurrentDate = MAX('Calendar'[Date]) VAR Step1 = [1 Step] VAR Step2 = [2 Step] RETURN IF( CurrentDate >= Step2 && CurrentDate <= Step1, 1, 0)
gives the correct values in the table, but it doesn't play nicely with the slicer. If I add it as a filter on the slicer then you can't select any dates at all. Not sure what's going on.
I have shared a sample file in message 13 of the thread. Sharing it again in this post.
If the calendar table is diconnected, then it will not be able to filter out data from the fact tables.
Here is a look at the data model. It is quite basic.
Your measure are a little too complex. Use these instead:
1 Step = EOMONTH(CALCULATE ( MAX ( 'Sales'[Sale Date] ), ALL () ),-1) 2 Step = EOMONTH([1 Step], - [Parameter Value] ) + 1
Take a look at the September 2023 Power BI update to learn more.
Join Microsoft Reactor and learn from developers.
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!
Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.