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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Filter data based on trendtype

Hello All,

 

I have a data like below having trendtype daily,weekly and monthly.

So I applied filter on trendtype.

If user selects trendtype as Daily then need to show only last 30 days

   If user selects   trendtype as Weekly then need to show only last 12 weeks

   If user selects    trendtype as Monthly then need to show only last 12 Months

 

Could any one please help how to do this

 

 

TrendType            Date               Sales

Daily9/28/2022155
Daily9/29/202278
Daily9/30/20229
Daily10/1/20226
Daily10/2/20225
Daily10/3/20223
Daily10/4/20222
Daily10/5/20224
Daily10/6/20229
Weekly9/25/2022190
Weekly10/2/2022180
Weekly10/9/2022200
Weekly10/16/2022260
Monthly7/1/20221666
Monthly8/1/20225787
Monthly9/1/20223456

 

 

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

Hi @Anonymous ,

 

You can try this method:

TrendType Slicer = VALUES('Trends'[TrendType])

Use these to create a new table to be a slicer.

Then in the Trend table create a measure:

Filter Flag =
VAR _day =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), DAY )
VAR _week =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), WEEK )
VAR _month =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), MONTH )
RETURN
    SWITCH (
        MAX ( 'TrendType Slicer'[TrendType] ),
        "Daily",
            IF ( _day >= 0 && _day <= 30, 1, 0 ),
        "Weekly",
            IF ( _week >= 0 && _week <= 12, 1, 0 ),
        "Monthly",
            IF ( _month >= 0 && _month <= 12, 1, 0 )
    )

 

Then add the measure in the filter:

vyinliwmsft_0-1667210184765.png

vyinliwmsft_1-1667210233469.png

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

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-yinliw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can try this method:

TrendType Slicer = VALUES('Trends'[TrendType])

Use these to create a new table to be a slicer.

Then in the Trend table create a measure:

Filter Flag =
VAR _day =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), DAY )
VAR _week =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), WEEK )
VAR _month =
    DATEDIFF ( MAX ( 'Trends'[Date] ), TODAY (), MONTH )
RETURN
    SWITCH (
        MAX ( 'TrendType Slicer'[TrendType] ),
        "Daily",
            IF ( _day >= 0 && _day <= 30, 1, 0 ),
        "Weekly",
            IF ( _week >= 0 && _week <= 12, 1, 0 ),
        "Monthly",
            IF ( _month >= 0 && _month <= 12, 1, 0 )
    )

 

Then add the measure in the filter:

vyinliwmsft_0-1667210184765.png

vyinliwmsft_1-1667210233469.png

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

amitchandak
Super User
Super User

@Anonymous , I think you need buttons and bookmarks

bookmark -https://blog.crossjoin.co.uk/2018/04/20/dynamically-changing-a-chart-axis-in-power-bi-using-bookmarks-and-buttons/
https://radacad.com/bookmarks-and-buttons-making-power-bi-charts-even-more-interactive

 

Also field parameter can help

use Date, weekstart date , month year as axis field parameters and then change measure based on selected value.

 

How to switch measure I discussed here

https://amitchandak.medium.com/switch-topn-with-field-parameters-299a0ae3725f

 

 

measure will be

var _max = maxx(allselected(Date1),Date1[Date])
var _mind = _max - 30 

var _minw = _max - 72

var _minm = eomonth(_max,-12) +1  

Switch([selected Axis],

"Date", calculate(sum(Table[Value]), filter(Date, Date[Date] >= _mind && Date[Date] <= _max)) ,

"Week Start Date", calculate(sum(Table[Value]), filter(Date, Date[Date] >= _minw && Date[Date] <= _max)),

calculate(sum(Table[Value]), filter(Date, Date[Date] >= _minm && Date[Date] <= _max))

)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.