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

find how many store dont buy a product as required conditions

Hi friends,

I have 2tables Order( ORderdate, Product_ID, Quantity, Store_ID)

and table Store(Store_ID, StoreName)

I need to count how many store that didnt order Product"A" 2 consecutive days from the fist day of month up to today!.

I think that i need to use datebetween function to calculate the days between 2 order times of each store but i am unable to do that because a store can buy product"A" in different dates and i didnt know the startdate and enddate !...

Could anyone give me some advices on my issue?

 

Regards,
J.

1 ACCEPTED SOLUTION

@MichaelJackpbi

 

According to your description, you want to filter Stores with no orders on specific product in 2 consecutive days each month. Right?

 

Firstly, please summarize your table to avoid duplicate dates for same Store. You can either use SUMMARIZECOLUMNS() function or "Group On" in Query Editor.

67.PNG

66.PNG

 

We can create a calculated column to identify if contains "exceeding 2 consecutive days" within a Group. Please refer to formula below:

 

IsNotMeet = 
IF(
DAY(Table2[OrderDate])=1 || DAY(Table2[OrderDate])=2,
0,
IF(
LOOKUPVALUE(Table2[Qty],Table2[OrderDate],Table2[OrderDate]-1,Table2[Store],Table2[Store]) = BLANK() 
&& 
LOOKUPVALUE(Table2[Qty],Table2[OrderDate],Table2[OrderDate]-2,Table2[Store],Table2[Store]) =BLANK(),
1,0)
)

99.PNG

 

 

Then you can just filter the data where IsNotMeet is not zero.

 

09.PNG

 

Another approach is getting the MAX date before the current date. You can add a calculated column like below:

 

Max Date Before Current Ddate = 
IF(
CALCULATE(MAX(Table2[OrderDate]),FILTER(Table2,Table2[OrderDate]<EARLIER(Table2[OrderDate]) && Table2[Store]=EARLIER(Table2[Store]) && Table2[Product]=EARLIER(Table2[Product])))=BLANK(),
DATE(YEAR(Table2[OrderDate]),MONTH(Table2[OrderDate]),1),
CALCULATE(MAX(Table2[OrderDate]),FILTER(Table2,Table2[OrderDate]<EARLIER(Table2[OrderDate]) && Table2[Store]=EARLIER(Table2[Store]) && Table2[Product]=EARLIER(Table2[Product]))))

96.PNG

 

Then just compare the different between the Order Date with the "Max Date Before Curernt Date" to determine if exceeds 2 consecutive days, this calcualted column works same as "IsNotMeet".

 

IsNotMeet2 = IF(DATEDIFF(Table2[Max Date Before Current Ddate],Table2[OrderDate],DAY)>=2,1,0)

989.PNG

 

 

Regards,

View solution in original post

6 REPLIES 6

This one is a little tricky to work through conceptually.  Can you provide some sample data (csv or excel format)?

 

Thanks

OrderDateProductQtyStore
2/12/2016A123
2/12/2016A113
3/12/2016A223
6/12/2016A53
7/12/2016A23
4/12/2016A232
5/12/2016A32
6/12/2016A312
7/12/2016A2232
2/12/2016A211
3/12/2016A231
4/12/2016A21
5/12/2016A121
6/12/2016A1231
7/12/2016A1241

 

 

Hi @dkay84_PowerBI

 

I can not attach the excel file, i uploaded a image that capturing my excel file. In my sample, i filter Product to "A" only and sort the Store. In fact, my boss needs every store has to sell a product everyday in a selected month.

I.e. This month he selectes product A to put into the strategy, so at the end of month i has to capture stores that order product A everyday and stores that didnot order product A 2 consecutive days.

For my example- assuming 7/12/2016 is the last of month, you can see that Store 3 ordered product A in day 2,3 and day 6/7 --> it means store 3 was not meet the condition because it was not order A in day 4 and day 5

Store 2 ordered product A in day 4/5/6/7 --> it also was not meet the condition because it did not order in day 1,2,3

Store 1 ordered product A in all of day( day 1,2,3,4,5,6,7) --> store 1 meet the condition

 

__result : I need some reports as:

 

          
 StoreDays didn’t  order A  days didn’t order A
Don’t meet 32  1day2 days3days4days>4days
 2 3 01100
Total2        
meet10       
Total10  days didn’t order B
     1day2 days3days4days>4days
     01100
          
          
     days didn’t order C
     1day2 days3days4days>4days
     01100

Two additional questions:

 

1.  Is the 30 day period rolling or by month?

 

2.  Is "not ordering for 2 consecutive days" the same as ordering every day?  Or can a store miss one day and that is okay?

@dkay84_PowerBI

I'd like to answer you as:

1. It depends on the first day of month end currentdate! we just care about current month .

2. Yes! we capture stores that miss more than 2 days at least, and miss days but not consecutive is okay!

 

Looking for your advice 🙂

Regards,
J.

Has anyone help me  ?:(

@MichaelJackpbi

 

According to your description, you want to filter Stores with no orders on specific product in 2 consecutive days each month. Right?

 

Firstly, please summarize your table to avoid duplicate dates for same Store. You can either use SUMMARIZECOLUMNS() function or "Group On" in Query Editor.

67.PNG

66.PNG

 

We can create a calculated column to identify if contains "exceeding 2 consecutive days" within a Group. Please refer to formula below:

 

IsNotMeet = 
IF(
DAY(Table2[OrderDate])=1 || DAY(Table2[OrderDate])=2,
0,
IF(
LOOKUPVALUE(Table2[Qty],Table2[OrderDate],Table2[OrderDate]-1,Table2[Store],Table2[Store]) = BLANK() 
&& 
LOOKUPVALUE(Table2[Qty],Table2[OrderDate],Table2[OrderDate]-2,Table2[Store],Table2[Store]) =BLANK(),
1,0)
)

99.PNG

 

 

Then you can just filter the data where IsNotMeet is not zero.

 

09.PNG

 

Another approach is getting the MAX date before the current date. You can add a calculated column like below:

 

Max Date Before Current Ddate = 
IF(
CALCULATE(MAX(Table2[OrderDate]),FILTER(Table2,Table2[OrderDate]<EARLIER(Table2[OrderDate]) && Table2[Store]=EARLIER(Table2[Store]) && Table2[Product]=EARLIER(Table2[Product])))=BLANK(),
DATE(YEAR(Table2[OrderDate]),MONTH(Table2[OrderDate]),1),
CALCULATE(MAX(Table2[OrderDate]),FILTER(Table2,Table2[OrderDate]<EARLIER(Table2[OrderDate]) && Table2[Store]=EARLIER(Table2[Store]) && Table2[Product]=EARLIER(Table2[Product]))))

96.PNG

 

Then just compare the different between the Order Date with the "Max Date Before Curernt Date" to determine if exceeds 2 consecutive days, this calcualted column works same as "IsNotMeet".

 

IsNotMeet2 = IF(DATEDIFF(Table2[Max Date Before Current Ddate],Table2[OrderDate],DAY)>=2,1,0)

989.PNG

 

 

Regards,

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.