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
EugeneNel83
Frequent Visitor

Sales identified that were made during promo campaigns

Hi All

 

I've been trying to lookup if sales were made on promo or not. 

 

The promo table has unique time periods but multiple times that a code is on promo.  I'll include a simplified example of what the tables look like below:

Sales Table  
CodeDateQty
123452022/04/151
123452022/07/032
1234562022/01/015

 

Promo Table  
CodeDate StartDate End
123452022/03/012022/03/31
123452022/07/012022/07/22
1234562019/12/012019/12/31

 

 

The result should look like this where the promo lines are identified  :

Sales Table  Added Column
CodeDateQtyOn Promo
123452022/04/151FALSE
123452022/07/032TRUE
1234562022/01/015FALSE

 

 

I'm trying to adapt this code below to include a logical lookup for rows that meet the date range and then product code to return the rows. Then I would like to add a True or False if on promo or not. 

 

Sales=
ADDCOLUMNS(
Sales,
"OnPromo",
VAR SalesDate =
SalesTable[Date]
RETURN
IF(LOOKUPVALUE (
IF(PromoTable[StartDate]>=SalesDate&&PromoTable[EndDate]<=SalesDate), SalesDate
Promo[Code], Sales[Code]),"True","False"),
)

 

Kind regards

Eugene

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @EugeneNel83 

Thanks for reaching out to us.

>>

You can try this measure, 

On Promo = IF( CALCULATE(COUNTROWS(PromoTable),FILTER(PromoTable,PromoTable[Code]=MIN(SalesTable[Code]) && PromoTable[Date Start]<=MIN(SalesTable[Date]) && PromoTable[Date End]>=MIN(SalesTable[Date])))=BLANK(),false,TRUE)

vxiaotang_1-1659339437476.png

 

 if you need a column, try this,

column = IF( CALCULATE(COUNTROWS(PromoTable),FILTER(PromoTable,PromoTable[Code]=EARLIER(SalesTable[Code]) && PromoTable[Date Start]<=EARLIER(SalesTable[Date]) && PromoTable[Date End]>=EARLIER(SalesTable[Date])))=BLANK(),false,TRUE)

vxiaotang_2-1659339504139.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @EugeneNel83 

Thanks for reaching out to us.

>>

You can try this measure, 

On Promo = IF( CALCULATE(COUNTROWS(PromoTable),FILTER(PromoTable,PromoTable[Code]=MIN(SalesTable[Code]) && PromoTable[Date Start]<=MIN(SalesTable[Date]) && PromoTable[Date End]>=MIN(SalesTable[Date])))=BLANK(),false,TRUE)

vxiaotang_1-1659339437476.png

 

 if you need a column, try this,

column = IF( CALCULATE(COUNTROWS(PromoTable),FILTER(PromoTable,PromoTable[Code]=EARLIER(SalesTable[Code]) && PromoTable[Date Start]<=EARLIER(SalesTable[Date]) && PromoTable[Date End]>=EARLIER(SalesTable[Date])))=BLANK(),false,TRUE)

vxiaotang_2-1659339504139.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Thanks Xiotang- perfect! Much appreciated

amitchandak
Super User
Super User

@EugeneNel83 , A new column in the sales table

 

column =

var _cnt = countx(promo, promo[code] = sales[code] && promo[start Date] <= sales[Date] && promo[End Date] >= sales[Date] ),promo[code])
return
if(isblank(_cnt), false(), True())

Thanks Amit, I get an error  on the promo[code]. It says the syntax for ',' is incorrect.  Is there a way around this?

 

 

EugeneNel83_0-1658990964154.png

 

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.

Top Solution Authors