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
Anonymous
Not applicable

Create last x days/weeks/month in dropdown filter

Hi, 

I'm looking to create a dropdown date filter with choices like ; 

 

filterfilter

 

Last 7 days

Last 2 weeks

Last month

...and so on

 

This will act like a date filter on respective visuals. Please let me know if this is possible in PowerBI

.

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

Hi @Anonymous 

 

You can create several measures list the 

Last 7 days

Last 2 weeks

Last month

...and so on

 

 and then try something like this:

Final Value 1 = 
IF(HASONEFILTER(Table[slicer]),
    SWITCH(SELECTEDVALUE(Table[slicer]),
        "Last 7 days", [Measure 1],
        "Last 2 weeks", [Measure 2],
        "Last month", [Measure 3]
    ),
   BLANK()
)

 

here're also other similar threads could be your reference:

https://community.powerbi.com/t5/Desktop/Control-Range-Date-by-Dropdown-filter/m-p/977818 

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

2 REPLIES 2
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

You can create several measures list the 

Last 7 days

Last 2 weeks

Last month

...and so on

 

 and then try something like this:

Final Value 1 = 
IF(HASONEFILTER(Table[slicer]),
    SWITCH(SELECTEDVALUE(Table[slicer]),
        "Last 7 days", [Measure 1],
        "Last 2 weeks", [Measure 2],
        "Last month", [Measure 3]
    ),
   BLANK()
)

 

here're also other similar threads could be your reference:

https://community.powerbi.com/t5/Desktop/Control-Range-Date-by-Dropdown-filter/m-p/977818 

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
MFelix
Super User
Super User

Hi @Anonymous ,

 

Believe that you need to create a auxiliar table with the information and then make a switch measure to filter out your information something similar to:

 

ID Type Period Type of Period
1 Last Week 7 Day
2 Last 2 Weeks 7 Day
3 Last Month 1 Month

 

Then make a formula similar to:

 

Measure =
CALCULATE (
    [Measure],
    SWITCH (
        SELECTEDVALUE ( Table[ID] ),
        1, FILTER (
            ALL ( DateTable ),
            DateTable[Date] <= MAX ( DateTable[Date] )
                && DateTable[Date] <= DATEADD ( DateTable[Date], - MAX ( Table[Period] ), DAY ),
2, .....

        )
    )
)

 

So you can dinamically add dates.

 

If you want some more details can you please share a sample data?

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.