Forum Discussion

hugomatos's avatar
hugomatos
New Member
1 year ago
Solved

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 72000...
  • d_m_LNK's avatar
    1 year ago

    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

  • Jihwan_Kim's avatar
    1 year ago

    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]
    )
    
  • mdaatifraza5556's avatar
    1 year ago

    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.