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
jalaomar
Helper IV
Helper IV

Dynamic date filter

Hi BI experts,

 

Anyone who can support me with how to create a dynamic date filter as per the following request.

 

View Rolling 7 months in which 4 weeks in the past, current week and 26 weeks in the future?

 

also would be good to allow users to select their own custom date range but always have above as default.

 

anyone please?

 

 

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

Hi  @jalaomar ,

I created some data:

vyangliumsft_0-1675239120700.png

 

Here are the steps you can follow:

1. Enter data – Create table.

vyangliumsft_1-1675239120701.png

2. Create measure.

Rolling 7 months =
var _month=
DATEDIFF(
MAX('Table'[Date]),TODAY(),MONTH)
return
IF(
    _month>=1&&_month<=7,1,0)
4 weeks in the past =
var _week=
DATEDIFF(
MAX('Table'[Date]),TODAY(),Week)
return
IF(
    _week>=1&&_week<=4,1,0)
current week =
var _week=
DATEDIFF(
MAX('Table'[Date]),TODAY(),Week)
return
IF(
    _week=0,1,0)
26 weeks in the future =
var _week=
DATEDIFF(
TODAY(),MAX('Table'[Date]),Week)
return
IF(
    _week>=1&&_week<=26,1,0)
Flag =
SWITCH(
    TRUE(),
    MAX('Slicer Table'[Slicer])="Rolling 7 months",[Rolling 7 months],
    MAX('Slicer Table'[Slicer])="4 weeks in the past",[4 weeks in the past],
    MAX('Slicer Table'[Slicer])="current week",[current week],
    MAX('Slicer Table'[Slicer])="26 weeks in the future",[26 weeks in the future])
SumValue =
IF(
    MAX('Slicer Table'[Slicer])="Rolling 7 months",
    SUMX(FILTER(ALLSELECTED('Table'),
    MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Rand]),
    MAX('Table'[Rand]))

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_2-1675239120702.png

4. Result:

Rolling 7 month:

vyangliumsft_3-1675239120703.png

4 weeks in the past:

vyangliumsft_4-1675239120705.png

 

Best Regards,

Liu Yang

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

Hi  @jalaomar ,

I created some data:

vyangliumsft_0-1675239120700.png

 

Here are the steps you can follow:

1. Enter data – Create table.

vyangliumsft_1-1675239120701.png

2. Create measure.

Rolling 7 months =
var _month=
DATEDIFF(
MAX('Table'[Date]),TODAY(),MONTH)
return
IF(
    _month>=1&&_month<=7,1,0)
4 weeks in the past =
var _week=
DATEDIFF(
MAX('Table'[Date]),TODAY(),Week)
return
IF(
    _week>=1&&_week<=4,1,0)
current week =
var _week=
DATEDIFF(
MAX('Table'[Date]),TODAY(),Week)
return
IF(
    _week=0,1,0)
26 weeks in the future =
var _week=
DATEDIFF(
TODAY(),MAX('Table'[Date]),Week)
return
IF(
    _week>=1&&_week<=26,1,0)
Flag =
SWITCH(
    TRUE(),
    MAX('Slicer Table'[Slicer])="Rolling 7 months",[Rolling 7 months],
    MAX('Slicer Table'[Slicer])="4 weeks in the past",[4 weeks in the past],
    MAX('Slicer Table'[Slicer])="current week",[current week],
    MAX('Slicer Table'[Slicer])="26 weeks in the future",[26 weeks in the future])
SumValue =
IF(
    MAX('Slicer Table'[Slicer])="Rolling 7 months",
    SUMX(FILTER(ALLSELECTED('Table'),
    MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Rand]),
    MAX('Table'[Rand]))

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_2-1675239120702.png

4. Result:

Rolling 7 month:

vyangliumsft_3-1675239120703.png

4 weeks in the past:

vyangliumsft_4-1675239120705.png

 

Best Regards,

Liu Yang

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

@v-yangliu-msft 

Super! Many thanks!

 

Mvh

Jala

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.