Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.
Good morning,
I am very new to Power Bi. I am trying to write an if statement for the below data. I have tried copying the syntax from other similar inquiries on this site, but no luck. What I am trying to do:
If YN NUMBER = "#N/A" then BIN NUMBER = "#N/A
But if YN NUMBER = "YNA0372094 or any other YN Number on the spreadsheet" then BIN NUMBER = "Active Not Sourced"
I have included the syntax for what I have been trying, but i just keep coming up with a screen that says "false"
Any help is greatly appreciated!!
Solved! Go to Solution.
Hi @DROG1025 , anothe solution you could try: I have taken certain assumptions here:
1. YN Number being your first column. If that's not the case, let me know and I'll send the edited version.
Here's the code:
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"YN NUMBER", type text}, {"BIN NUMBER", type text}}),
RecAsList = Table.TransformRows(#"Changed Type", each _ & [BIN NUMBER = if Text.End(Record.FieldValues(_){0},1) = "A" then "NA" else "Active Not Sourced"]),
Table = Table.FromRecords(RecAsList)
in
Table
Hi @DROG1025
We would like to confirm that the solution provided by @SundarRaj is accurate and resolves the issue. Could you please confirm if your query has been resolved? If it has, kindly mark the helpful response and accept it as the solution. This will help other community members resolve similar issues more efficiently. If not, please provide detailed information so we can assist you better.
Thank you
Hi @DROG1025 , anothe solution you could try: I have taken certain assumptions here:
1. YN Number being your first column. If that's not the case, let me know and I'll send the edited version.
Here's the code:
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"YN NUMBER", type text}, {"BIN NUMBER", type text}}),
RecAsList = Table.TransformRows(#"Changed Type", each _ & [BIN NUMBER = if Text.End(Record.FieldValues(_){0},1) = "A" then "NA" else "Active Not Sourced"]),
Table = Table.FromRecords(RecAsList)
in
Table
@DROG1025 To create an if statement in Power BI using DAX (Data Analysis Expressions), you can use the IF function. Based on your requirements, you want to check the value of YN NUMBER and assign a value to BIN NUMBER accordingly.
DAX
BIN NUMBER =
IF(
[YN NUMBER] = "#N/A",
"#N/A",
"Active Not Sourced"
)
If you want to modify the existing BIN NUMBER column based on the condition without adding a new column in Power Query, you can use the "Replace Values" feature with a custom formula. Here’s how you can do it:
Open your Power BI Desktop.
Go to the "Home" tab and click on "Transform Data" to open Power Query Editor.
Select the column BIN NUMBER.
Go to the "Transform" tab and click on "Replace Values".
In the "Replace Values" dialog box, click on the small arrow next to the "Replace" button and select "Replace Using Formula".
Enter the following formula in the "Replace Using Formula" dialog box:
m
if [YN NUMBER] = "#N/A" then "#N/A" else "Active Not Sourced"
Click "OK".
Proud to be a Super User! |
|
@bhanu_gautam it does not appear that I have the small arrow next to the replace button. Screenshot below
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.