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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
hugomatos
New Member

Creating new column based on value from another table

Hi everyone,

 

I have 2 tables and I need to create a column on the second based on values from the first. Some ideia? 

 

table1

START CODE       END CODE      INFO     
71000007200000INFO 1
70000007099999INFO 2
73000007399999INFO 3

 

table2

ID                    Name                           NEW COLUMN NEEDED                  
7101010SOMEONE INFO 1
7302202NEW PERSONINFO 3
7033300DOGINFO 2

 

I need to add a new column on table2 that comes from table1[info] using as criteria that Table2[ID] should be between table1[start code] and table1[end code] and then return table1[info] to be placed as a new column on table2.

Important: the ranges table1[start] and table1[end] are uniques.

 

Thanks.

6 REPLIES 6
v-mdharahman
Community Support
Community Support

Hi @hugomatos,

Thanks for reaching out to the Microsoft fabric community forum.

It looks like you are looking for a way to add a column from one table to another. As @sevenhills@mdaatifraza5556@Jihwan_Kim and @d_m_LNK all responded to your query, please go through the responses and mark the helpful reply as solution.

 

I would also take a moment to thank @sevenhills@mdaatifraza5556, @Jihwan_Kim and @d_m_LNK for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.

 

If I misunderstand your needs or you still have problems on it, please feel free to let us know.  

Best Regards,
Hammad.
Community Support Team

 

If this post helps then please mark it as a solution, so that other members find it more quickly.

Thank you.

Hi @hugomatos,

As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.

If yes, you are welcome to share your workaround and mark it as a solution so that other users can benefit as well. If you find a reply particularly helpful to you, you can also mark it as a solution.


If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.
Thank you for your patience and look forward to hearing from you.

sevenhills
Super User
Super User

Try this, add column to Table2:

Column = SUMMARIZE( FILTER( Table1, Table2[ID] >= Table1[START CODE] && Table2[ID] <= Table1[END CODE]), Table1[INFO]) 

 

Output: (Table 2)

sevenhills_0-1742597223022.png

 

mdaatifraza5556
Resolver II
Resolver II

Hi @hugomatos 

Can you please try the below DAX.

New Column =
VAR MatchingRow =
    FILTER(
        table1,
        Table1[START CODE ] <= Table2[ID] &&
        Table2[ID] <= Table1[END CODE ]
    )
RETURN
    MAXX(MatchingRow, Table1[INFO])


If you have found your answer, please mark it as the solution.
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1742530493102.png

 

 

expected result CC = 
SUMMARIZE (
    FILTER (
        Table1,
        Table1[START CODE] <= Table2[ID]
            && Table1[END CODE] >= Table2[ID]
    ),
    Table1[INFO]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

d_m_LNK
Resolver I
Resolver I

You could create a calculated DAX Column on table 2 for this.  You would could create an ID for your code ranges and add them to your table1.  Then with your caclulated column calculate what ID to assign each row and then relate the ID of table1 to the calculated ID of table2 Something like:


VAR RowID = Table2[ID]
VAR FilteredTable =
FILTER('Table1',
AND('Table1'[StartCode] <= RowID,
'Table1'[EndCode] >=RowID
)
)
VAR Result =
CALCULATE(
DISTINCT('Table1'[IDRangeKey]), FilteredTable)
RETURN Result

 

Once that is created you can access that info column through the newly created relationship

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors