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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Nested If Statement PowerQuery

Hi need help with a  nested if statetment. 

I have a table with a Location_code and Unit. Need the follwoing if statement in power query

IF the location code is "130" or "600" then replace all the unit values with the word "Mixed" else show the original unit value.

1 ACCEPTED SOLUTION

@Anonymous 

Modified:

 

if ([Location_Code] = 130 or [Location_Code] = 600) and [Units] = "IPO" then [Units] else if ([Location_Code] = 130 or [Location_Code] = 600) then "Mixed" else [Units]

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

7 REPLIES 7
ChrisMendoza
Resident Rockstar
Resident Rockstar

Here it is if you do not want to add an additional column:

= Table.ReplaceValue(#"Changed Type",each [Unit], each if [Location_code] = 130 or [Location_code] = 600 then "Mixed" else [Unit] ,Replacer.ReplaceText, {"Unit"})

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

Sample Code that may help your case from Microsofts documentation.  It also depends if your using DAX or Power Query as the coding is completely different.

DAX:

Price Group = IF( 'Product'[List Price] < 500, "Low", IF( 'Product'[List Price] < 1500, "Medium", "High" ) )

IF function (DAX) - DAX | Microsoft Docs

Fowmy
Super User
Super User

@Anonymous 

Do you need a new column? Hope you have two column Location_Code and the Units. If you have numbers in units, why do you want to have text in that as "mixed" ?


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Yes, it will be a new column and the Unit is text not numbers oringinaly. Example Unit: GRE, ADO, or ADU.

@Anonymous 

Click on Custom Column and add the following code:

if [Location_Code] = 130 or [Location_Code] = 600 then "Mixed" else [Units]

Fowmy_0-1623096133924.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

OK add complexity. Forgot to include the logic if Unit equals IPO then Unit. So Location codes that are 130 or 600 and the unit is IPO then UNit else if the Location Code is 130 or 600 then Mixed

@Anonymous 

Modified:

 

if ([Location_Code] = 130 or [Location_Code] = 600) and [Units] = "IPO" then [Units] else if ([Location_Code] = 130 or [Location_Code] = 600) then "Mixed" else [Units]

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.