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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
bmccaslin
Regular Visitor

Filtering Sales Data Between Friday 5pm - Monday 4am

Hello, 

 

 I'm currently looking to filter out sales data that falls between Friday at 5pm and Monday at 4am. Is there a DAX that can accomplish this?

2 ACCEPTED SOLUTIONS
techies
Solution Sage
Solution Sage

Hi @bmccaslin please check this

 

Create a calculated column

 

Sales_Weekend_Filter =
VAR SaleDateTime = Sheet2[DateTime]  
VAR SaleDay = WEEKDAY(SaleDateTime, 2)
VAR SaleTime = TIME(HOUR(SaleDateTime), MINUTE(SaleDateTime), SECOND(SaleDateTime))

RETURN
    IF(
        (SaleDay = 5 && SaleTime >= TIME(17, 0, 0)) ||
        (SaleDay = 6) ||
        (SaleDay = 7) ||
        (SaleDay = 1 && SaleTime <= TIME(4, 0, 0)),
        "Exclude",
        "Include"
    )
 
and the measure 
 
Filtered_Sales =
CALCULATE(
    SUM(Sheet2[Sales Amount]),
    Sheet2[Sales_Weekend_Filter] = "Include"
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

View solution in original post

v-kpoloju-msft
Community Support
Community Support

Hi @bmccaslin,
Thank you for reaching out to the Microsoft fabric community forum. Thank you @techies, for your inputs on this issue.

Calculated Column:

IsWeekendSalesWindow =

VAR WeekdayNumber = WEEKDAY(Sales[SalesDateTime], 2)  -- Monday=1, Sunday=7

VAR TimeOnly = TIME(HOUR(Sales[SalesDateTime]), MINUTE(Sales[SalesDateTime]), SECOND(Sales[SalesDateTime]))

RETURN

    SWITCH(TRUE(),

        -- Friday after 5 PM

        WeekdayNumber = 5 && TimeOnly >= TIME(17,0,0), TRUE,

        -- Saturday anytime

        WeekdayNumber = 6, TRUE,

        -- Sunday anytime

        WeekdayNumber = 7, TRUE,

        -- Monday before 4 AM

        WeekdayNumber = 1 && TimeOnly < TIME(4,0,0), TRUE,

        FALSE

    )

Dax Measure:

SalesOutsideWeekendWindow =
CALCULATE(
SUM(Sales[SalesAmount]),
FILTER(
Sales,
NOT (
VAR WeekdayNumber = WEEKDAY(Sales[SalesDateTime], 2)
VAR TimeOnly = TIME(HOUR(Sales[SalesDateTime]), MINUTE(Sales[SalesDateTime]), SECOND(Sales[SalesDateTime]))
RETURN
SWITCH(TRUE(),
WeekdayNumber = 5 && TimeOnly >= TIME(17,0,0),
TRUE(),
WeekdayNumber = 6,
TRUE(),
WeekdayNumber = 7,
TRUE(),
WeekdayNumber = 1 && TimeOnly < TIME(4,0,0),
TRUE(),
FALSE()
)
)
)
)

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

View solution in original post

5 REPLIES 5
v-kpoloju-msft
Community Support
Community Support

Hi @bmccaslin,
Thank you for reaching out to the Microsoft fabric community forum. Thank you @techies, for your inputs on this issue.

Calculated Column:

IsWeekendSalesWindow =

VAR WeekdayNumber = WEEKDAY(Sales[SalesDateTime], 2)  -- Monday=1, Sunday=7

VAR TimeOnly = TIME(HOUR(Sales[SalesDateTime]), MINUTE(Sales[SalesDateTime]), SECOND(Sales[SalesDateTime]))

RETURN

    SWITCH(TRUE(),

        -- Friday after 5 PM

        WeekdayNumber = 5 && TimeOnly >= TIME(17,0,0), TRUE,

        -- Saturday anytime

        WeekdayNumber = 6, TRUE,

        -- Sunday anytime

        WeekdayNumber = 7, TRUE,

        -- Monday before 4 AM

        WeekdayNumber = 1 && TimeOnly < TIME(4,0,0), TRUE,

        FALSE

    )

Dax Measure:

SalesOutsideWeekendWindow =
CALCULATE(
SUM(Sales[SalesAmount]),
FILTER(
Sales,
NOT (
VAR WeekdayNumber = WEEKDAY(Sales[SalesDateTime], 2)
VAR TimeOnly = TIME(HOUR(Sales[SalesDateTime]), MINUTE(Sales[SalesDateTime]), SECOND(Sales[SalesDateTime]))
RETURN
SWITCH(TRUE(),
WeekdayNumber = 5 && TimeOnly >= TIME(17,0,0),
TRUE(),
WeekdayNumber = 6,
TRUE(),
WeekdayNumber = 7,
TRUE(),
WeekdayNumber = 1 && TimeOnly < TIME(4,0,0),
TRUE(),
FALSE()
)
)
)
)

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Hi @bmccaslin,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you.

Hi @bmccaslin,


I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


Thank you.

Hi @bmccaslin,


I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.


Thank you.

techies
Solution Sage
Solution Sage

Hi @bmccaslin please check this

 

Create a calculated column

 

Sales_Weekend_Filter =
VAR SaleDateTime = Sheet2[DateTime]  
VAR SaleDay = WEEKDAY(SaleDateTime, 2)
VAR SaleTime = TIME(HOUR(SaleDateTime), MINUTE(SaleDateTime), SECOND(SaleDateTime))

RETURN
    IF(
        (SaleDay = 5 && SaleTime >= TIME(17, 0, 0)) ||
        (SaleDay = 6) ||
        (SaleDay = 7) ||
        (SaleDay = 1 && SaleTime <= TIME(4, 0, 0)),
        "Exclude",
        "Include"
    )
 
and the measure 
 
Filtered_Sales =
CALCULATE(
    SUM(Sheet2[Sales Amount]),
    Sheet2[Sales_Weekend_Filter] = "Include"
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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