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
Cognosben
Frequent Visitor

Dynamic Date Filter

Is it possible to create a dynamic date filter in a DAX expression where the result would be to have filter selections you can click for:

- Year to Date

- Last Month

- Last Week 

- Last Day

 

 

 

 

 

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

HI @Cognosben,

 

 

I'd like to suggest you take a look at below link which has the similar requirement:

Calculating Averages for the same data for different time buckets (Daily/Weekly/Monthly)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @Cognosben,

 

 

I'd like to suggest you take a look at below link which has the similar requirement:

Calculating Averages for the same data for different time buckets (Daily/Weekly/Monthly)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @Anonymous

Thank you for reply. 

 

I have created the help table and the measure underneath but cannot get it to work. The measures are not showing when I put FilterMeasure into a graph. The individual measures are working as they should. What might be wrong?

 

FilterMeasure = IF(HASONEVALUE(Filter_Date[Filter]);SWITCH(VALUES(Filter_Date[Filter]);"YTD";[YTD_Number];"MTD";[YTM_Number];[YTD_Number]))

 

 

Anonymous
Not applicable

Hi @Cognosben

Does the FilterMeasure work outside of a graph? In a table for example or in Card visual?

In the graph, what dates do you have on the axis? Could you post a picture or link a file and i can have a look.

Best regards,
Gustav

Anonymous
Not applicable

Hi,

If I understand you correct you would want to do something like this.

One measure that changes depending on the datefilter you have filtered?

My suggestion is as follows:

Create a table (DatefilterTable) that has the following columns

SortKey DateFilter
1 YTD
2 Last Month
3 Last Week
4 Last Day

Sortkey is not needed but can be useful if you want a specific sortorder.

Create a measure for each YTD, Last Month, Last Week, Last Day filter.
Example [Measure YTD], [Measure Last Month]..

Finally you create:
FilterMeasure = IF(HASONEVALUE(DatefilterTable[DateFilter]),SWITCH(VALUES(DatefilterTable[DateFilter),"YTD",[Measure YTD],"Last Month",[Measure Last Month],"Last Week",[Measure Last Week],"Last Day",[Measure Last Day],[Your Default Measure])


[Your Default Measure] can be any of the above measures. It will display when you have no filter selected.

The DateFilter column can then be used in a slicer 🙂

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.