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
Anonymous
Not applicable

Calculate values between dates - unrelated tables (many-to-many)

Hi!

 

I have 4 tables : Sales, Product, Date, and Promotion, and I want to calculate money made between the dates in Promotion table. I've made a dummy dataset to replicate mine:

 

BobBnks_0-1664368720683.png

 

 

The "Value" in Sales is total money made on each transaction, excluding any promotion discount.

 

BobBnks_1-1664368790166.png

 


All tables are joined to Sales, except Promotion. I tried, but it causes a many-to-many relationship. I also tried to create an index to each transation in the Sales table and join to Promotion, but this resulted in circular dependancy.


The problem is that each promotion contains several products, so there is no unique ID:

BobBnks_2-1664368846216.png

 

What do you think is the best solution? It feels that joining it to Sales is the best (star schema) but it doesn't work for me. Is it possible? Or should I join Promotion to Product and Date, and use then DAX measures?

Thank you for any advice!

1 ACCEPTED SOLUTION

Is it possible for you to share your pbi file so we can help you out?

 

Maybe try this as a calculated column:

 

PromotionID = CALCULATE(
   VALUES(DimPromotion[PromotionID),
   FILTER(DimPromotion,
   'Sales'[Date] >= 'DimPromotion'[StartDate]
   && 'Sales'[Date] < 'DimPromotion'[EndDate]
   && 'DimPromotion'[ProductID] = 'Sales'[ProductID]
   ))

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

I was missing that last filter. Now I'm able to join Promotions to Sales - thank you!

jcalheir
Solution Supplier
Solution Supplier

Hi

 

I feel like your best solution would be to have a PromotionID in the sales table. In order to do that you will need to join both tables by Product and a date range.

How exactly have you tried to join both Sales and Promotions table? Have you tried in Power Query? Ou directly in your data source?

 

Kind regards,
José
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

Anonymous
Not applicable

Hi Jose,

 

Besides trying to join ProductID to ProductID (many-to-many), I created a calculated column "PromotionID" in Sales using DAX:

 

PromotionID = CALCULATE(
   VALUES(DimPromotion[PromotionID),
   FILTER(DimPromotion,
   'Sales'[Date] >= 'DimPromotion'[StartDate]
   && 'Sales'[Date] <= 'DimPromotion'[EndDate]
   ))
 
This gave me a new column in which the PromotionID appeared for each transaction within the promotion period. It's blank for any transactions not involved in the promotion. When I joined it to Promotion this resulted in circular dependancy.
 
I'm very new to power bi, so thanks for any help!

Is it possible for you to share your pbi file so we can help you out?

 

Maybe try this as a calculated column:

 

PromotionID = CALCULATE(
   VALUES(DimPromotion[PromotionID),
   FILTER(DimPromotion,
   'Sales'[Date] >= 'DimPromotion'[StartDate]
   && 'Sales'[Date] < 'DimPromotion'[EndDate]
   && 'DimPromotion'[ProductID] = 'Sales'[ProductID]
   ))

 

 

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.