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
briguin
Helper I
Helper I

How do I generate a Y/N column if a product was in or out of promotion (Effective Dates)

I have products that go in and out of promotion throughout the year. I have 2 tables, Sales and Effective Dates.

I would create a column to flag if an item was in or out of promotion during a specific time period.

Then create a measure to do my math. My desired result is the chart below.

briguin_0-1624237962287.png

 

I manually created the far right "Was_Promoted" column , Can it be done in DAX?

Sales table:

ProductDateTotal_SalesTotal_NotSoldWas_Promoted
Prod101/01/21100251
Prod101/02/21200101
Prod101/03/211000 
Prod101/04/2140001
Prod101/05/21500201
Prod101/06/21100301
Prod201/01/2140050 
Prod201/02/2150025 
Prod201/03/21200101
Prod201/04/21100201
Prod201/05/2170030 
Prod201/06/2110010 

 

Promotion Effective Date

ProductStart_DateEnd_Date
Prod101/01/2101/02/21
Prod101/04/2101/06/21
Prod201/03/2101/04/21

 

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @briguin 

 

I thought you wanted a Calculated column for this manually created "Was_Promoted", a disconnected promotion table

Vera_33_0-1624253804271.png

Was_Promoted = 
VAR CurProduct = SalesTable[Product]
VAR CurDate = SalesTable[Date]
VAR T1=FILTER(PromotionTable,PromotionTable[Product]=CurProduct&&PromotionTable[Start_Date]<=CurDate&&PromotionTable[End_Date]>=CurDate)
RETURN
COUNTROWS(T1)

 

View solution in original post

4 REPLIES 4
Vera_33
Resident Rockstar
Resident Rockstar

Hi @briguin 

 

I thought you wanted a Calculated column for this manually created "Was_Promoted", a disconnected promotion table

Vera_33_0-1624253804271.png

Was_Promoted = 
VAR CurProduct = SalesTable[Product]
VAR CurDate = SalesTable[Date]
VAR T1=FILTER(PromotionTable,PromotionTable[Product]=CurProduct&&PromotionTable[Start_Date]<=CurDate&&PromotionTable[End_Date]>=CurDate)
RETURN
COUNTROWS(T1)

 

parry2k
Super User
Super User

@briguin yes that prod_dim doesn't need much except this table will have unique product values to set the relationship between promotion and sales table.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@briguin it will make more sense to have a Product dimension that has a unique product and have a relationship with both the tables, one to many.

 

and then add this custom column in Sales Table.

 

Promoted = 
VAR __table = CALCULATETABLE ( Promotion )
VAR __sales = CALCULATETABLE ( Sales ) 
VAR __promotionCount = COUNTX ( CROSSJOIN ( __sales, __table ), IF ( Sales[Date] >= [Start_Date] && Sales[Date] <= [End_Date], 1 ) )
RETURN IF (  ISBLANK ( __promotionCount ), "No", "Yes" )

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k 

I think you are saying I need a 3rd table, a Prod_Dim.

What additional information would you put in a Prod_Dim table? 

 

Prod1 is a unique key. We sale the same Product all year we just promote it differently behind the scenes.

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.