Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to use a dynamic string variable

Hi guys,

 

Hope you can help me, i have this table:

edgarcalgary_0-1595963928484.png

 

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

edgarcalgary_1-1595964212129.png

 

 

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?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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 )

How to use a dynamic string variable_calculated column.JPG

Best Regards

Rena

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Community Champion
Community Champion

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

 

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



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
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:

 

edgarcalgary_0-1595966754803.png

 

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

@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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Any slightly idea where i should apply it?

Anonymous
Not applicable

Hi @Anonymous ,

Please try to update the formula of measure as below:

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

How to use a dynamic string variable.JPG

Best Regards

Rena

Anonymous
Not applicable

Hi @Anonymous ,

 

Thanks for your answer, i already tried that way before with the result but, i see in your example you have two "JJ", so basically how would you add the 1 value in all the JJ's in the column?

Anonymous
Not applicable

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 )

How to use a dynamic string variable_calculated column.JPG

Best Regards

Rena

@Anonymous I don't understand why we are all after creating the column when measure can do the job. Do we understand the difference between creating measure vs columns and how it has an impact on the model?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@Anonymous @Anonymous solution should work, not sure why is not showing 1 for each JJ operator, I created sample data and used following measure 

 

 

Top Operator = 
VAR __topId = CALCULATE ( MAX ( Well[Id] ), ALL (  Well ) )
VAR __topOpertor = CALCULATE ( MAX ( Well[Operator] ), Well[Id] = __topId )
RETURN IF ( MAX ( Well[Operator] ) = __topOpertor, 1, 0 )

 

 

 

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.

edgarcalgary_0-1595966589654.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.