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
rvnaresh
Microsoft Employee
Microsoft Employee

Try to use OR function with if and text contains

Hi, I want to categorize the datacenter to a region like the table below and use it in one of my reports. 

 

DatacenterLocation
ABC01Europe
ABC02Europe
ACB01Europe
ACB02Europe
BAC01AMER
BAC02AMER
BDA01AMER
BDA02AMER
CAB01APAC
CAB02APAC
CDA01APAC
CDA02APAC

 

I am trying to use OR function in this context and I don't get the results. Please help.

 

"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Region",

each if Text.Contains([Data Center], OR("AB*, AC*") then "Europe"

else if Text.Contains([Data Center], OR("BA*, BD*") then "Americas"

else if Text.Contains([Data Center], OR("CA*, CD*") then "APAC"

else "Uncategorized")

 

Thanks,

Naresh

6 REPLIES 6
rvnaresh
Microsoft Employee
Microsoft Employee

Thank you for the solutions. 

 

Will I be not able to call the function with multiple values in at a time? I have over 50 datacenters that needs categorization and the code looks cumbersome

 

It will be easy if I provide the the values in a single function rather than taking up multiple lines.

such as:

 

if Text.Contains([Data Center], OR("AB*, AC*") then "Europe"

 

or 

 

if Text.StartsWith([Data Center],OR("AB*", "AC*") then "Europe"

 

 

or 

 

if StartString = or("AB*", "AC*) then "Europe"

 

 

Hi @rvnaresh 

 

Download example PBIX file

 

Yes you could write this as a function, called FindRegion

 

(DataCenter as text) => 

let 
    DC = Text.Start(DataCenter , 2),
    Regions = [
                AB = "Europe",
                AC = "Europe",
                BA = "Americas",
                BD = "Americas",
                CA = "APAC",
                CD = "APAC"
                ],

    Source = if Record.HasFields(Regions, DC) then Record.Field(Regions, DC) else "Uncategorized"

in
    Source

 

 

You'll need to add all of the data center codes and regions to the Regions record in this function.

 

You can then call it in a new Custom Column like this

 

= FindRegion([Data Center])

 

regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks Phil..

 

will give it a try

Hello,

 

Wouldn't it make sense to have a separate lookup table in which you start all the datacenters and join this to the main table? This increases flexibility as i think an if clause is not best stuiable if you have over 50 cases.

 

 

Papermain
Frequent Visitor

Hello,

 

Please add the following code in a custom column:

 

let 
StartString = Text.Upper(Text.Start([Column1],2))
in 
if StartString = "AB" or StartString =  "AC" then "Europe"

else if StartString = "BA" or StartString = "BD" then "Americas"

else if StartString = "CA" or StartString = "CD" then "APAC"

else "Uncategorized"
PhilipTreacy
Super User
Super User

Hi @rvnaresh 

 

Download example PBIX file

 

Use the Text.StartsWith function and or like this

 

 

if Text.StartsWith([Data Center],"AB") or Text.StartsWith([Data Center], "AC") then "Europe"

else if Text.StartsWith([Data Center],"AB") or Text.StartsWith([Data Center], "BD") then "Americas"

else if Text.StartsWith([Data Center],"CA") or Text.StartsWith([Data Center], "CD") then "APAC"

else "Uncategorized"

 

 

regs.png

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.