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

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.

Reply
Anonymous
Not applicable

Facing issues with the IF statement

Hi All,

 

Below is the table and the following formula is used in excel. The logic is straightforward in excel. I am trying to find the Gender based on values present in column A and B. 

Formula - =IF(A2=B2,"No Data",IF(A2="","Female","Male"))

Sri1990_1-1675045055878.png

Now, I try to do the same in power BI with similar data, the query doesnt work. I read IF statements work in Power BI.

Following queries have been tried by creating a custom column:

Query 1:

Gender = if([FEMALE_AGE_RANGE]=[MALE_AGE_RANGE],"No Data", if([FEMALE_AGE_RANGE]="null","Male","Female")

Sri1990_2-1675045576335.png

 

Query 2:

Gender = if [FEMALE_AGE_RANGE]=[MALE_AGE_RANGE]
then "No Data"
else if( [FEMALE_AGE_RANGE]="null"
then "male"
else "female"

Sri1990_3-1675045657847.png

Can someone please guide me what I am doing wrong and appreciate if someone can provide me a right query using IF statement.

 

Thank you

 

 

 

1 ACCEPTED SOLUTION
mussaenda
Super User
Super User

Hi @Anonymous ,

 

try 

if [FEMALE_AGE_RANGE] = [MALE_AGE_RANGE]
then "No Data"
else 

if [FEMALE_AGE_RANGE] = null
then "Male"
else
"Female"

View solution in original post

4 REPLIES 4
mussaenda
Super User
Super User

Hi @Anonymous ,

 

try 

if [FEMALE_AGE_RANGE] = [MALE_AGE_RANGE]
then "No Data"
else 

if [FEMALE_AGE_RANGE] = null
then "Male"
else
"Female"
Anonymous
Not applicable

Hi @mussaenda

 

Thanks for this. It worked so the only difference between your query and my query is that extra space between "else" and "if" 😐 ? and how did you find out about this issue? I did not even think in your direction at all. Thanks again

Hi @Anonymous ,

 

Glad it worked. It is still your query. 

The difference is the null that you treated as a string because of ""

 

It should be null and not "null"

 

Anonymous
Not applicable

Thanks mate. Clear 🙂 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors