{"id":1683,"date":"2023-01-20T19:02:28","date_gmt":"2023-01-20T19:02:28","guid":{"rendered":"https:\/\/monocroft.com\/?p=1683"},"modified":"2023-03-03T08:31:50","modified_gmt":"2023-03-03T08:31:50","slug":"how-to-convert-yesno-to-1-0","status":"publish","type":"post","link":"https:\/\/monocroft.com\/how-to-convert-yesno-to-1-0\/","title":{"rendered":"How to Convert Yes\/No to 1\/0 in Power BI"},"content":{"rendered":"\n
In Power BI, there are different ways to convert Yes\/No<\/strong> values to 1\/0<\/strong> using various functions such as the SWITCH<\/strong>, or IF functions<\/strong>. <\/p>\n\n\n\n Regardless of the method you choose, you will need to create a new column in your table to hold the converted values. And once the new column is created, you can make use of it in your visualizations and reports.<\/p>\n\n\n\n In this article, I will explain some of these methods to convert Yes\/No to 1\/0 <\/strong>when working with Power BI.<\/p>\n\n\n\n Let’s get started.<\/p>\n\n\n\n To use the IF function, make sure you already have your data inserted into Power BI Desktop. Then select the dataset that contains the Yes\/No column.<\/p>\n\n\n\n After this, go to the Modeling<\/strong> tab<\/strong> and click on New Column<\/strong>.<\/p>\n\n\n\n In the formula bar, enter the following formula:<\/p>\n\n\n\n Where And Then press Enter <\/strong>to create the new column. This will convert the Yes\/No values to 1 and 0, respectively in a new column.<\/p>\n\n\n\n (As displayed below when you click on the data<\/strong> tab)<\/em><\/p>\n\n\n\n Also, you can as well use the SWITCH function to convert Yes\/No to 1\/0 by using this formula:<\/p>\n\n\n\n Where Column<\/strong> stands for the name of the new column that will be created.<\/em><\/p>\n\n\n\n And Save the changes and you are done! The new column will now contain only 1’s and 0’s<\/strong>, and you can see this in the data tab (as displayed below).<\/em><\/p>\n\n\n\n Finally, always keep in mind that regardless of the method you choose to use, you will create a new column in your table to hold the converted values. And once the new column is created, you can use it in your visualizations and reports.<\/p>\n\n\n\n Also, you can rename the column to something more meaningful instead of the default name.<\/p>\n\n\n\n NB: You can also use the Replace Values<\/strong> in Power Query Editor to replace Yes with 1 and No with 0 if you have a large number of rows. To do this, go to the Home tab<\/strong>, select Edit Queries<\/strong>, and then select Replace Values<\/strong>.<\/em><\/p>\n\n\n\n I hope you understood these steps.<\/p>\n\n\n\n Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":" In Power BI, there are different ways to convert Yes\/No values to 1\/0 using various functions such as the SWITCH, … <\/p>\nUsing the IF Function<\/h2>\n\n\n\n
<\/figure>\n\n\n\n
Column = IF(Sheet1[Type] = \"Yes\", 1, 0)<\/strong><\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
Column<\/strong> <\/code>stands for the name of the new column that will be created.<\/em><\/p>\n\n\n\n
Sheet1[Type]<\/strong><\/code> is the name of the column where my Yes\/No<\/strong> value is stored in the dataset.<\/em><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Using the SWITCH function<\/h2>\n\n\n\n
Column = SWITCH(Sheet1[Type], \"Yes\", 1, \"No\", 0)<\/code><\/strong><\/pre>\n\n\n\n
Sheet1[Type]<\/strong><\/code> is the name of the column where the new Yes\/No<\/strong> value is stored in the dataset.<\/em><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Conclusion: How to Convert Yes\/No to 1\/0 in Power BI<\/h2>\n\n\n\n