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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
SHenderosn
Frequent Visitor

Current week date filter applied to all days between two dates

I'm trying to add a slicer for filtering down PTO requests that fall within the current week, but I can't get it to filter correctly. 

 

My data set is pretty simple and includes a start and end date for each PTO request.  I also have full calendar/date table with a "CurrentWeekOffset" column that I use for filtering. There is a relationship between the PTO Start Date my date table.

 

The problem, is that when I try to filter to a CurrentWeekOffset of "0" (i.e., date falls within current week), it only looks at the related Start Date and hides any PTO requests that may have started last week but are ongoing this week.  

 

Full Data Set:

 

EmployeeStart DateEnd Date
Justin3/28/244/9/24
John 3/29/244/5/24
Deja 4/1/244/5/24
Benjamin4/3/244/8/24
Latisha4/15/244/23/24
Melissa4/29/245/7/24
Carie5/15/245/22/24

 

 

What it currently shows for Current Week as 3/31/24-4/6/24:

 

EmployeeStart DateEnd Date
Deja 4/1/244/5/24
Benjamin4/3/244/8/24

 

 

What it should show:

 

EmployeeStart DateEnd Date
Justin3/28/244/9/24
John 3/29/244/5/24
Deja 4/1/244/5/24
Benjamin4/3/244/8/24

 

In this example, Justin and John's PTO start dates were last week, but they are still on vacation this week and should show up when I filter it to current week PTO.

 

How do set up my data and relationships so that when I filter to Current Week, it shows all rows where there is any day between Start and End Date that falls in the current week? 

2 ACCEPTED SOLUTIONS
TheoC
Super User
Super User

Hi @SHenderosn 

 

You should be able to achieve this by adding a calculated column in your PTO table that checks whether the specific record is in the current week or not. This column can then be used as a Slicer to filter whether a PTO falls within the Current Week. 

 

Just update the below to your table and column names and it should work well.  You can then add this as a slicer and achieve your desired output. 

 

PTO_In_Current_Week = 

VAR _start = 

	CALCULATE ( 
		MIN ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

VAR _end = 

	CALCULATE ( 
		MAX ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

RETURN

IF (
    AND (
        'PTOTable'[Start Date] <= _end , 
        'PTOTable'[End Date] >= _start ) ,
    "Current Week" , "Not Current Week"
	)

)

 

Hope this works okay!

 

Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

View solution in original post

This is exactly what I needed, thank you!

View solution in original post

5 REPLIES 5
TheoC
Super User
Super User

@SHenderosn also, there is a really great post by @v-jiascu-msft (Dale) that provides a very simple solution to achieve your desired output as well in the form of a calculated column.  You can refer to it here:

 

https://community.fabric.microsoft.com/t5/Desktop/Determine-if-date-is-between-2-dates/m-p/314685

 

Again, you can use the calculated column as a Slicer to achieve the requirements you are after and adjust the output in Dale's solution.

 

Have a great day and all the best!

 

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

TheoC
Super User
Super User

Hi @SHenderosn 

 

You should be able to achieve this by adding a calculated column in your PTO table that checks whether the specific record is in the current week or not. This column can then be used as a Slicer to filter whether a PTO falls within the Current Week. 

 

Just update the below to your table and column names and it should work well.  You can then add this as a slicer and achieve your desired output. 

 

PTO_In_Current_Week = 

VAR _start = 

	CALCULATE ( 
		MIN ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

VAR _end = 

	CALCULATE ( 
		MAX ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

RETURN

IF (
    AND (
        'PTOTable'[Start Date] <= _end , 
        'PTOTable'[End Date] >= _start ) ,
    "Current Week" , "Not Current Week"
	)

)

 

Hope this works okay!

 

Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

This is exactly what I needed, thank you!

Ashish_Mathur
Super User
Super User

Hi,

I have solved a similar problem in the attached file.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TheoC
Super User
Super User

Hi @SHenderosn 

 

You should be able to achieve this by adding a calculated column in your PTO table that checks whether the specific record is in the current week or not. This column can then be used as a Slicer to filter whether a PTO falls within the Current Week. 

 

You will need to update the table and column names to match your model but hopefully this will work for what you are trying to achieve.  By doing it this way, you should be okay to leave your relationships etc as is.

 

PTO_In_Current_Week = 

VAR _start = 

	CALCULATE ( 
		MIN ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

VAR _end = 

	CALCULATE ( 
		MAX ( 'DateTable'[Date] ) , 'DateTable'[CurrentWeekOffset] = 0 
		)

RETURN

IF (
    AND (
        'PTOTable'[Start Date] <= _end , 
        'PTOTable'[End Date] >= _start ) ,
    "Current Week" , "Not Current Week"
	)

)

 

Hope this works okay!

 

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.