Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to use a dynamic string variable

Hi guys,

 

Hope you can help me, i have this table:

 

the data is not always sorted so, i am looking for the operator name where the id is the highest: this the following i was able to get the operator name by max wellid,

_CURRENT = 
VAR TOPWELL = MAX('Well List'[WellID])
VAR _topclient = 
CALCULATE(MAX('Well List'[Operator]), KEEPFILTERS( FILTER( ALL('Well List'[WellName], 'Well List'[Operator], 'Well List'[WellID]), 'Well List'[WellID] = TOPWELL)))
return _topclient

 

 

how can i identify in the main table the all the operators with the name as result of the measure? i tried:

IF( _topclient IN VALUES(Operator name), 1, 0)

 

but this returns all values as 1. Any idea?

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous ,

    Please try to create a calculated column with below formula to replace the original measure:

    Column = 
    VAR _topclient =
        CALCULATE (
            MAX ( 'Well List'[Operator] ),
            FILTER (
                ALL ( 'Well List' ),
                'Well List'[WellID] = MAX ( 'Well List'[WellID] )
            )
        )
    RETURN
        IF (  'Well List'[Operator]  = _topclient, 1, 0 )

    Best Regards

    Rena

11 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Anonymous - Not sure I completely understand, but perhaps this:

     

    Measure = IF(MAX([Operator]) = [_CURRENT],1,0)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Greg_Deckler ,

       

      Thanks for your answer, i still got the same result as 1, i know Max will be interating row by row but wondering why not recognizing the _topclient variable.

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      if i just return the variable _topclient :

      _CURRENT = 
      VAR TOPWELL = MAX('Well List'[WellID])
      VAR _topclient = 
      CALCULATE(MAX('Well List'[Operator]), KEEPFILTERS( FILTER( ALL('Well List'[WellName], 'Well List'[Operator], 'Well List'[WellID]), 'Well List'[WellID] = TOPWELL)))
      return _topclient

      the result is this:

       

       

       so seems it is filtering row by row and not giving the proper result.

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Anonymous - I'm still now 100% clear but you may need an ALL or ALLEXCEPT in there to break out of the current context of the visual/row.