Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Return multiple values from a column based on duplicates

I have a measure that calculates and returns a scalar MAX from a column.

Using this MAX value, I want to return a concatenated string from another column, especially if the table has duplicates.

 

For e.g. there are duplicate scores of 3 in the table 'PlayerScore' below. I want to use the output to be a concatenated string - 'Jason, Bob'. The reason I want it in this format is to use it within the Smart Narrative widget. 

I tried doing it with LOOKUPVALUE but that returns an error as multiple values are returned. 

 

My attempt was:

maxScore = CALCULATE(MAX(PlayerScore[Score])) #this returns 3

 

result = 

LOOKUPVALUE(PlayerScore[Name],PlayerScore[Score],PlayerScore[maxScore]) #this throws an error as multiple values are returned

 

Expected output - Jason, Bob

 

Table: 'PlayerScore'

 

NameScore
Jason3
Bob3
Nancy1
  • Hey Anonymous,

    try this code. For me it worked perfectly.

    Measure = CONCATENATEX( Filter('PlayerScore',PlayerScore[Score] = Max(PlayerScore[Score])),PlayerScore[Name] ,", ")

     

5 Replies

  • Hey Anonymous,

    try this code. For me it worked perfectly.

    Measure = CONCATENATEX( Filter('PlayerScore',PlayerScore[Score] = Max(PlayerScore[Score])),PlayerScore[Name] ,", ")

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you!

    • TOK's avatar
      TOK
      Helper II

      I just finished a short tutorial on this topic.

       

  • smpa01's avatar
    smpa01
    Community Champion

    Anonymous  try this

    _concat =
    CONCATENATEX (
        FILTER (
            tbl,
            CALCULATE ( COUNT ( tbl[Name] ), ALLEXCEPT ( tbl, tbl[Score] ) ) > 1
        ),
        tbl[Name],
        ",",
        tbl[Name], ASC
    )
    

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for responding. But this solution doesn't work at 'scale', as the table can have any number of rows. 

       

      NameScore
      Jason3
      Bob3
      Nancy1
      Paul5
      Eric3
      Devon5
      Alex5

      and so on..

       

      I want to get all the names with max score (which could be change depending on new data) and return it as a string.  For the above example, now 5 is the max score and the expected output would be 'Paul, Devon, Alex'. 

       

      Apologies if I wasn't clear in my original post!