cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rate Regular Visitor
Regular Visitor

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

Accepted Solutions
ofirk Regular Visitor
Regular Visitor

Re: Open or Closed by Store & Day

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")

2 REPLIES 2
ofirk Regular Visitor
Regular Visitor

Re: Open or Closed by Store & Day

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")

Rate Regular Visitor
Regular Visitor

Re: Open or Closed by Store & Day

Hello @ofirk,

 

Just awesome. Thanks a lot!!

Helpful resources

Announcements
GregDeckler

How to Get Your Question Answered Quickly

Power BI Super User, Greg Deckler, explains

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Ideas
Users Online
Currently online: 27 members 912 guests
Please welcome our newest community members: