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
Rate
Helper III
Helper III

Open or Closed by Store & Day

Hello!

 

I have a list stores with different opening/closing times, both store by store and by day of the week. I would like to generate a column that defines if a sale that has been recorded in a specific store was done within the hours the store was open to the public or when it should be closed.

 

I have started testing with a formula for Monday-Saturday, but I would like to extract the opening/closing time from a different table, depending on the store that has registered the sale.

 

Open-Closed Monday-Saturday = IF(Sales[Day_of_Week]    <>   "Sunday";
    if   (HOUR(Sales[Hour]) >= 9 && HOUR(Sales[Hour]) <= 21 ; "Open"; "Closed");"ERROR")

Do you have any idea how to (vastly) improve the formula?

 

Thanks a lot!

1 ACCEPTED SOLUTION
ofirk
Resolver II
Resolver II

Hi @Rate,

How about:

Create 2 tables,

1. containing store data ('StoreData'), with columns:

- Store

- Opening (hour)

- Closing (hour)

- ClosedDay

 

2. for transactions ('Transactions'), with columns:

- Store

- TransactionDayOfWeek

- TransactionHour

 

The tables should have a relationship on the Store column. 

Then, you can create the following column in the Transactions table:

 

open_or_closed = IF([TransactionDayOfWeek] <> RELATED(StoreData[ClosedDay]) && [TransactionHour] >= RELATED(StoreData[Opening]) && [TransactionHour] < RELATED(StoreData[Closing]), "Open", "Closed")

View solution in original post

2 REPLIES 2
ofirk
Resolver II
Resolver II

Hi @Rate,

How about:

Create 2 tables,

1. containing store data ('StoreData'), with columns:

- Store

- Opening (hour)

- Closing (hour)

- ClosedDay

 

2. for transactions ('Transactions'), with columns:

- Store

- TransactionDayOfWeek

- TransactionHour

 

The tables should have a relationship on the Store column. 

Then, you can create the following column in the Transactions table:

 

open_or_closed = IF([TransactionDayOfWeek] <> RELATED(StoreData[ClosedDay]) && [TransactionHour] >= RELATED(StoreData[Opening]) && [TransactionHour] < RELATED(StoreData[Closing]), "Open", "Closed")

Hello @ofirk,

 

Just awesome. Thanks a lot!!

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.