Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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.
Solved! Go to Solution.
@billuran2009
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]
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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"})
Proud to be a Super User!
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
@billuran2009
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" ?
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Yes, it will be a new column and the Unit is text not numbers oringinaly. Example Unit: GRE, ADO, or ADU.
@billuran2009
Click on Custom Column and add the following code:
if [Location_Code] = 130 or [Location_Code] = 600 then "Mixed" else [Units]
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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
@billuran2009
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]
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |