Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

TOPN on rows

Hi friends,
Look in this table

IDValue1Value2Value3Reslut
1105115
220102040
330151747
440201860


I have tried to get the two highest values from Value1, Value2 and Value3 and Sum this in the Result for each row on that ID.
But i dont mangae to solve this.

Is there any out there who can help me.

  • Hi Anonymous 

     

    You need to create a new colunm (not measure) in your table. See sample DAX. 

    TopNSum =
    VAR v1 = 'Table'[Value1]
    VAR v2 = 'Table'[Value2]
    VAR v3 = 'Table'[Value3]
    VAR SortedValues =
        TOPN(2, {v1, v2, v3}, [Value])
    RETURN
        SUMX(SortedValues, [Value])
     
    If I answered your question, please mark this thread as accepted.
    Follow me on LinkedIn:
    https://www.linkedin.com/in/mustafa-ali-70133451/

2 Replies

  • amustafa's avatar
    amustafa
    Icon for Solution Sage rankSolution Sage

    Hi Anonymous 

     

    You need to create a new colunm (not measure) in your table. See sample DAX. 

    TopNSum =
    VAR v1 = 'Table'[Value1]
    VAR v2 = 'Table'[Value2]
    VAR v3 = 'Table'[Value3]
    VAR SortedValues =
        TOPN(2, {v1, v2, v3}, [Value])
    RETURN
        SUMX(SortedValues, [Value])
     
    If I answered your question, please mark this thread as accepted.
    Follow me on LinkedIn:
    https://www.linkedin.com/in/mustafa-ali-70133451/
  • Anonymous's avatar
    Anonymous
    Not applicable

    amustafa 
    Thanks alot!
    You made my day a little bit better 🙂