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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mcolb88
Helper III
Helper III

Dynamic Date Filter

I have all of my visualzations based on a date range. I show a variety of measures based on the date, but want to limit the date to the range between the start and end date of a campaign. I have a slicer that allows the user to pick the cam paign and the campaiogn dimension has start and end dates. How can I limit (filter) the visualization, page and/or report to only show dates in the range of the selected campaign?

 

There doesn't seem to be an oiption for a dynamic filter (really unfortunate).

 

Trying to figure out a way to use a DAX CalculatedTable and a relationship to my date dimension but haven;'t gotten that to work yet either.

 

Any suggestions are greatly appreciated.

6 REPLIES 6
DoubleJ
Solution Supplier
Solution Supplier

Following is my suggestion.

 

I created a small sample consisting of 2 tables. Please don't be confused by the German date format, it's read dd.mm.yyyy.

First table contains the campaings:
01.PNG

 

 

 

 

 

Second table contains the data to be analyzed, in my sample a simple sales table:

02.PNG

 

 

 

 

 

 

 

 

 

You can create a simple slicer with the campaings, as you already did.

 

In your measures you can add a test condition that checks whether there's excatly ONE campaign selected in your slicer. The trick is to use the HASONEVALUE() function. If it returns TRUE (meaning there is one campaign selected), narrow the results of your calculation with the start and end date of the selected campaign. Otherwhise just ignore the dates. A measure that sums up the Amounts looks like this:


SalesAmount = IF(
    HASONEVALUE(Campaigns[CapaignId]),
    CALCULATE(
        SUM(Sales[Amount]),
        Sales[SalesDate] >= VALUES(Campaigns[StartDate]),
        Sales[SalesDate] <= VALUES(Campaigns[EndDate])),
    SUM(Sales[Amount]))

The results with different slicer selections:
1. No slicer selection:

03.PNG

2. "Campaign 1" selected:

 

04.PNG

 

3. "Campaign 2" selected:

04.PNG

 

This approach works if the user can only select one campaign in the slicer. If multiple selection is allowed this sample has to be enhanced.

 

Hope this helps!

JJ

 

 

 

 

 

JJ,

 

Appreciate the quick response. However, what I need to do is to limit the visualization from displaying dates past the end of the campaign. The x-axis is the date and the y-axis is two percentages. Once the campaign is over, the values will never change. The values are cumulative so every date has a value. I supposed I could check the date in the Measure and return blank once the end of the campaign is reached, then the chart may stop displaying dates past the end. This is what it looks like.

 

2017-02-24_15-42-05.png

 

This is a perfect example of adding a dynamic filter for the visualzation to be Call Date <= [Campaign End Date]. Other tools hve this ability.

 

 

 

Anonymous
Not applicable

Hi , was a solution founded for this problem ?

I see your point now.

 

I also would try to return blank values once the campaing end date is reached.

 

Hope you'll find a solution!

JJ

parry2k
Super User
Super User

May be add a calculate field on your calendar table called, "Within Campaign Date Range" and add filter on this field, check the syntax for following

 

WithinCampaignDateRange 
= if(Calendar[Date]>=Campaign[StartDate] && Calendar[Date]<=Campaign[EndDate], 1, 0)

Now on filter drop WithinCampignDateRange and put condition is 1

 

It will only show dates where value is 1. Just an idea.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Funny, had that thought too...

 

DateInCampaign =IF([Call Date] >= [Campaign Start Date] && [Call Date] <= [Campaign End Date], TRUE(), FALSE())

 

[Campaign Start Date] and [Campaign End Date] are measures calauclated as the min() and Max() of thoise dates in the scenario where mutliple campaigns are selected.

 

So I drop a table on a report showing the Call Date and DateInCampaign.

When I select a campaign, in the slicer, these Campaign Start and End change, but the values for DateInCampaign do not 😞

 

Thanks for the idea, this should work though right? Or are the calculated columns re-calculated at process time?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.