Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

If statement with string variable not working



I have data from Power Bi dataset, I need to create a measure using if then else for a string variable"regions". I basically need to create a measure(since I cannot create a new column) which would combine some regions and rename some regions. Both if and switch statements are unable to identify by col("Cannot find name"). I think I need to summaries it.


Just for testing, I used count for this field, powerbi identifies it but I need something to work on text fields. 


Super User
Super User

@pam259 , you need to use min , max or firstnonblank or lastnonblank or dimension value

example masure

color =
switch ( true(),
FIRSTNONBLANK(Table[commodity],"NA") ="commodity1" && sum(Table[Value]) >500,"lightgreen",
FIRSTNONBLANK(Table[commodity],"NA") ="commodity2" && sum(Table[Value]) >1000,"lightgreen",
/// Add more conditions


measure =
switch ( true(),
max(Table[region]) ="R1" , [Mea1],
max(Table[region]) ="R2", [Mea2],
/// Add more conditions


also refer

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
Super User
Super User

HI @pam259 ,


Not able to understand your query. Please share sample data along with expected output to understand your question here.




My Blog: Data Vibe
Connect: LinkedIn
Connect: Twitter

If this helps, Appreciate a KUDOS!
Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Super User
Super User

@pam259 If I understand correctly, use MAX or MIN as your aggregation. Not really enough information to go on, please first check if your issue is a common issue listed here:

Also, please see this post regarding How to Get Your Question Answered Quickly:

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

Solution Sage
Solution Sage

Dear @pam259 

Can you share some dummy data (3-4 rows ) and expected output

,You can use excel to show this , and just paste that things from excel in post section.

I will write and send you measure 👍



Thakur Sujit

Have field, "productname" values as ABC, AB,AA, etc. Need to convert values in a new measure like ABC=AB1, AB=AB2. Trying to use switch or IF, but field "productname" is not being identified


For row context and filter context understanding =


Keep learning my friend 


Dear @pam259 

You are having such issues because you didn't have included Aggregation function before your field . 

I would suggest you , if you want to change values like ABC=AB1, AB=AB2.


Use a calculated column, it will be more easy and helpful .

Use this 


Column = Switch (


[Product name] = "ABC" , "AB1",

[Product name] = "AB" ,"AB2",

"Else condition value "



Or if you are adhered using measure let me tell you my friend , for using any field in measure you must use aggregation function before it to tell power bi that from which rows you want calculation to happen.


But as column works  most of the time in row context hence no aggregation function will be required in calculated columns.


I hope you understand .


If any doubt let me know .


I do expect kudos to keep me motivated !!


If this post helped you to solve your problem then please accept it as solution.



Thakur Sujit



Thankyou so much.  I have data from powerbi datasets so I cannot create any new columns. What aggregation should I use for this string variable?

Super User
Super User

@pam259 very confusing what you are trying to do here. You need to provide some sample data and expected output. Read this post to get your answer quickly.

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.

Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.