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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
GH21
Frequent Visitor

Using Last 7/14 days as a filter

Hi,

 

I'm currently working on a report that has a visual of new contracts that are downloaded to a CSV file automatically updating every monday. I would like it show new contracts that have been added over the last week or 14 days maybe even the last month. 

 

Is there a way to do this, I'm still new to PowerBi but I'm picking stuff up as I go along.

 

Thanks in advance.

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

Hi  @GH21 ,

I created some data:

vyangliumsft_0-1670478184619.png

Here are the steps you can follow:

1. Enter data – create a table.

vyangliumsft_1-1670478184621.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table2'[Slicer])
var _today=TODAY()
return
SWITCH(
    TRUE(),
_select ="last week"&&MAX('Table'[Date]) >DATE(YEAR(_today),MONTH(_today),DAY(_today)-7)&&MAX('Table'[Date]) <=_today,1,
_select ="14 days" &&MAX('Table'[Date])>DATE(YEAR(_today),MONTH(_today),DAY(_today)-14)&&MAX('Table'[Date]) <=_today,1,
_select ="last month"&&MAX('Table'[Date])>EOMONTH(_today,-2)&&MAX('Table'[Date]) <=EOMONTH(_today,-1),1,0)

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

vyangliumsft_2-1670478184621.png

4. Result:

vyangliumsft_3-1670478184624.png

Related functions:

SWITCH function (DAX) - DAX | Microsoft Learn

SELECTEDVALUE function - DAX | Microsoft Learn

TODAY function (DAX) - DAX | Microsoft Learn

DATE function (DAX) - DAX | Microsoft Learn

 

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

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @GH21 ,

I created some data:

vyangliumsft_0-1670478184619.png

Here are the steps you can follow:

1. Enter data – create a table.

vyangliumsft_1-1670478184621.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table2'[Slicer])
var _today=TODAY()
return
SWITCH(
    TRUE(),
_select ="last week"&&MAX('Table'[Date]) >DATE(YEAR(_today),MONTH(_today),DAY(_today)-7)&&MAX('Table'[Date]) <=_today,1,
_select ="14 days" &&MAX('Table'[Date])>DATE(YEAR(_today),MONTH(_today),DAY(_today)-14)&&MAX('Table'[Date]) <=_today,1,
_select ="last month"&&MAX('Table'[Date])>EOMONTH(_today,-2)&&MAX('Table'[Date]) <=EOMONTH(_today,-1),1,0)

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

vyangliumsft_2-1670478184621.png

4. Result:

vyangliumsft_3-1670478184624.png

Related functions:

SWITCH function (DAX) - DAX | Microsoft Learn

SELECTEDVALUE function - DAX | Microsoft Learn

TODAY function (DAX) - DAX | Microsoft Learn

DATE function (DAX) - DAX | Microsoft Learn

 

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

amitchandak
Super User
Super User

@GH21 , refer if this solution can help

 

https://community.powerbi.com/t5/Desktop/Required-custom-date-Slicer-Last-7-days-last-15-days-last-3...

 

a measure like

 

Last 7 days =
var _max = maxx(allselected(Date),Date1[Date])
var _min = _max -7
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

Hi @amitchandak, thank you for this however i'm struggling to understand the logic for it.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.