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
RogerSteinberg
Post Patron
Post Patron

How to add a column from table B to table A if a value exist or not

Hi,

 

Assuming i have a date table:

Date 
1-Jan
2-Jan
3-Jan

 

And a sales table:

TdateSalesProductPromoFlag
1-Jan10SoccerN
2-Jan20TennisY
2-Jan20SoccerN
3-Jan15BasketballN


I need to append a column to the Date table as such : 

Date PromoPeriod
1-JanNo
2-JanYes
3-JanNo

 

Basically the yes should be computed by looking in the sales table to see if there was during that day at least one product with the "Y" flag . If so then the date should be Yes 

 

How can i do this ? 

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @RogerSteinberg 

 

Download sample PBIX file with the code below

 

In your 'Date' table you can create a column using this code

 

 

Column = IF(CALCULATE(COUNTROWS('Sales'), FILTER('Sales', 'Sales'[Tdate] = [Date] && 'Sales'[PromoFlag] = "Y"))>0,"Yes","No")

 

Screenshot 2021-03-25 094206.png

 

However there are a few things to mention.

When one talks about a Date Table in Power BI this usually means a table that contains dates and other time related information that is used as a date table for Time Intelligence calculations.  Not sure that is what you have?

If it is, you shouldn't be adding columns to it to as described above.

Do you really need this PromoPeriod added as a column in your table?  Would a measure work just as well?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

RogerSteinberg
Post Patron
Post Patron

very well explained and thank you for your suggestions at the end! 

View solution in original post

2 REPLIES 2
RogerSteinberg
Post Patron
Post Patron

very well explained and thank you for your suggestions at the end! 

PhilipTreacy
Super User
Super User

Hi @RogerSteinberg 

 

Download sample PBIX file with the code below

 

In your 'Date' table you can create a column using this code

 

 

Column = IF(CALCULATE(COUNTROWS('Sales'), FILTER('Sales', 'Sales'[Tdate] = [Date] && 'Sales'[PromoFlag] = "Y"))>0,"Yes","No")

 

Screenshot 2021-03-25 094206.png

 

However there are a few things to mention.

When one talks about a Date Table in Power BI this usually means a table that contains dates and other time related information that is used as a date table for Time Intelligence calculations.  Not sure that is what you have?

If it is, you shouldn't be adding columns to it to as described above.

Do you really need this PromoPeriod added as a column in your table?  Would a measure work just as well?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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