Forum Discussion

unknown917's avatar
unknown917
Icon for Helper IV rankHelper IV
1 year ago

Measure and lookup

I have 2 tables with a many to one relationship.  I need to lookup and ID from table 1, find it table 2, and return the MEASURE associated with the ID.

 

I have read that you cannot use a measure when using the LOOKUP function and I don't understand how RELATED will allow to return a value based on the related column.

 

Does anyone know a work around or a better solution to the dilemma?

 

Any help will be greatly appreciated.

6 Replies

  • could you pls provide some sample data and expected output?

  • Anonymous's avatar
    Anonymous
    Not applicable

    ryan_mayu , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

    Hi  unknown917 ,

    I created some data:

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    SUMX(
        FILTER(ALL('Table2'),'Table2'[ID]=MAX('Table1'[ID])),[Value])

    2. Result:

     

    If the results above don't meet your expectations, Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • unknown917's avatar
      unknown917
      Icon for Helper IV rankHelper IV

      The above measure resulted in 'Infinity'.

       

      Below is an example of my dataset.  

       

      Table 1
      ID
      1
      2
      3
      1
      4
      3
      2
      6
      7
      5
      5
      8

       

      Table 2 
      IDValue (measure)
      115
      223
      378
      454
      52
      636
      714
      85
      • unknown917's avatar
        unknown917
        Icon for Helper IV rankHelper IV

        To clarify again, I used the what if parameter for the purposes of data entry at the end user level.  The expected output would be:

         

        Table 1 
        IDOutput
        115
        223
        378
        115
        454
        378
        223
        636
        714
        52
        52
        85
  • I should clarify as well.  The measure is from a what if parameter.

     

    Thank youy

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  unknown917 ,

    Use the following measure in the sample data I created to show the correct values:

    Measure =
    SUMX(
        FILTER(ALL('Table2'),'Table2'[ID]=MAX('Table1'[ID])),[Value_Measure])

    Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

    Note: Power BI Table Visual will automatically aggregate duplicates, so to have all [IDs] in Table1 displayed, you can create an index in Power Query to set a separate label for each row.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.