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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.