1

Looking for some DAX guidance here, to return a text field based on the maximum returned by a measure appplied over that column.

i.e we have table[category_column] and [measure] and the measure references columns in other tables, with two-sided relationships.

Any help much appreciated, very stuck!

Thanks in advance

1
  • 1
    What have you tried so far? Can you provide some data and structure of your table so we understand your starting point and what you try to solve.
    – Aldert
    Commented Jan 15, 2020 at 20:11

2 Answers 2

2

If I'm reading right, I think you want to draw the measure against the column values and return the row with the max of the measure. Something like this?

newMeasure = 
    VAR vals = SUMMARIZE('Table', 'Table'[Column1], "myMeasure", [Measure])
    VAR measureMax = MAXX(vals, [myMeasure])
    VAR value = CALCULATE(MAXX(FILTER(vals, [myMeasure] = measureMax), [Column1]))
RETURN
    value  
4
  • Actually it's occurred to me you could probably simplify this by wrapping the summarised table in a TOPN with N =1 and ordered by the measure. Haven't had a chance to test though.
    – Rob C
    Commented Jan 17, 2020 at 16:07
  • Thank you Rob C! Firstly apologies for the delay, this project was on hold for a while and only just got to test the suggestion... which worked a treat and even answered the follow-up question which was how to return the nth highest category... which I can do with the TOPN suggestion and changing MAXX to MINX i.e TOPN(5,SUMMARIZE('Table', 'Table'[Column1], "myMeasure", [Measure]), [myMeasure]) and then MINX(vals, [myMeasure]) returns the text corresponding to the 5th highest value.
    – esteebie
    Commented Feb 4, 2020 at 17:22
  • ps Only thing I had to change was the variable name 'value' which I guess is a reserved keyword
    – esteebie
    Commented Feb 4, 2020 at 17:27
  • Thanks for this. Solved the problem I had!
    – damo
    Commented Aug 19, 2021 at 15:43
0

If your column to be used for max is Column1 and your text field is Column2 something like the below could work:

Measure = 
VAR Max_Value =max('Table'[Column1])
Return CALCULATE(MAX('Table'[column2]),'Table'[Column1]=Max_value)

If this is not what you are looking for you have to explain your requirements in further detail, hopefully with examples.

3
  • Thanks for responding CR7SMS. Because the values are coming from a measure not a column, this does not work unfortunately. In your code, substituting max('Table'[Column1]) with max([measure]) fails as max needs a column name.
    – esteebie
    Commented Jan 16, 2020 at 11:29
  • How is the measure getting calculated?
    – CR7SMS
    Commented Jan 16, 2020 at 15:12
  • Hi, the measure is fairly complicated - a weighted sum of four other measures, taking the weightings from tables that can be selected in a separate config tab. The 4 measures are also fairy involved (too complicated to paste into here I'd say) and all draw from different tables, but these are connected in the data model by the same category (Column2 as above).
    – esteebie
    Commented Jan 17, 2020 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.