Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DJ1977
Helper I
Helper I

Add column for campaign within daterange

Hello. I have a small case here that I can not find a solution to by searching the forum here. Hope someone can give me a tip.
I have a model with two tables, A & B, among several.

 

Tables.JPG

 

 

 

 

 

 

These two are not related. I want to add a column in Table B with Campaign from Table A. It should add campaign when hits on product, customer and sales date hits in validity within campaign date range.
Is there a DAX formula that can solve this?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(VALUES(Table1[Campaign]),FILTER(Table1,Table1[Customer]=EARLIER(Table2[Customer])&&Table1[Product ID]=EARLIER(Table2[Product ID])&&Table1[Start date]<=EARLIER(Table2[Salesdate])&&Table1[End date]>=EARLIER(Table2[Salesdate])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
v-shex-msft
Community Support
Community Support

HI @DJ1977,

It sounds like a general multiple date range analysis requirements, you can take a look at the following link 'start date', 'end date' part of it suitable for your sceniaro.

Before You Post, Read This 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@DJ1977 , Try this formula. As a new Dax column

minx(filter(TableA, TableA[StartDate] <=Tableb[SalesDate] && TableA[endDate] >=Tableb[SalesDate] && && TableA[productID] >=Tableb[productID]), TableA[]campaign])

 

Refer this video , how copy value from one table to another :https://www.youtube.com/watch?v=czNHt7UXIe8

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(VALUES(Table1[Campaign]),FILTER(Table1,Table1[Customer]=EARLIER(Table2[Customer])&&Table1[Product ID]=EARLIER(Table2[Product ID])&&Table1[Start date]<=EARLIER(Table2[Salesdate])&&Table1[End date]>=EARLIER(Table2[Salesdate])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur , and thank you very much for your answer. I tryed this solution, but i got an error telling me "DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."

 

Both Campaign and Customer are textcolumns. Is there a way i can go around this error?

 

Regards

DJ

HI @DJ1977,

It sounds like a common issue when you use the 'math' operators to compare with different types of values. Please check your two table date fields to confirm if they are correctly formatted as date types.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft  and thank you very much for your answer. This fixed the error and now i have a solution to my problem, with help of your tip and @Ashish_Mathur DAX formula above.

 

Regards

DJ

HI @DJ1977,

I'm glad to hear that my suggestion helps to solve the issue.🙂

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.