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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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