Forum Discussion
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 |
| 7100000 | 7200000 | INFO 1 |
| 7000000 | 7099999 | INFO 2 |
| 7300000 | 7399999 | INFO 3 |
table2
| ID | Name | NEW COLUMN NEEDED |
| 7101010 | SOMEONE | INFO 1 |
| 7302202 | NEW PERSON | INFO 3 |
| 7033300 | DOG | INFO 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.
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 ResultOnce that is created you can access that info column through the newly created relationship
Hi,
Please check the below picture and the attached pbix file.
expected result CC = SUMMARIZE ( FILTER ( Table1, Table1[START CODE] <= Table2[ID] && Table1[END CODE] >= Table2[ID] ), Table1[INFO] )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 ])RETURNMAXX(MatchingRow, Table1[INFO])
If you have found your answer, please mark it as the solution.
8 Replies
- Jihwan_KimSuper User
Hi,
Please check the below picture and the attached pbix file.
expected result CC = SUMMARIZE ( FILTER ( Table1, Table1[START CODE] <= Table2[ID] && Table1[END CODE] >= Table2[ID] ), Table1[INFO] ) - mdaatifraza5556Super User
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 ])RETURNMAXX(MatchingRow, Table1[INFO])
If you have found your answer, please mark it as the solution. - d_m_LNKSuper User
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 ResultOnce that is created you can access that info column through the newly created relationship
- sevenhillsSuper 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)
- AnonymousNot applicable
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 TeamIf this post helps then please mark it as a solution, so that other members find it more quickly.
Thank you.
- AnonymousNot applicable
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.- AnonymousNot applicable
Hi hugomatos,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution so that other community members can find it easily.
Thank you.