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
techtina
Frequent Visitor

Using IF function with DAX to classify account types

Hello all! I'm fairly new to using DAX and Power BI and I keep getting stumped using the IF function. 

 

I'm trying to create a new column in 'edit queries' where I'm trying to classify account codes by account type. Specifically, I have a column of Account Codes (7010, 7209, 7997, 8010, 8116, ect) and I want all the accounts beginning with 7 to be classified as "Personnel," and all the accounts beginning with 8 to be classified as "General". (All the account codes begin with 7 or 😎 

 

I assumed that I would be using an IF function, however, I'm not sure what the correct formatting is and I keep getting error messages particularly this one: DAX comparison operations do not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

I've tried many different functions. This is the latest one I've tried:

 

Column = IF(DimAccount[AccountCode]<=7999,"Personnel","General")

 

Any feedback would be much appreciated!

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

Hi @techtina make sure thar Account Codes columns is not a text field.




Lima - Peru

View solution in original post

jahida
Impactful Individual
Impactful Individual

@Vvelarde is almost certainly right; the workaround is just to change your formula to:

 

Column = IF(VALUE(DimAccount[AccountCode])<=7999,"Personnel","General")

 

However, I would say better practice might be:

 

Column = IF(LEFT(DimAccount[AccountCode]) = "7", "Personnel", "General")

 

just because it makes it a bit more clear to me. Your call.

View solution in original post

3 REPLIES 3
Vvelarde
Community Champion
Community Champion

Hi @techtina make sure thar Account Codes columns is not a text field.




Lima - Peru
jahida
Impactful Individual
Impactful Individual

@Vvelarde is almost certainly right; the workaround is just to change your formula to:

 

Column = IF(VALUE(DimAccount[AccountCode])<=7999,"Personnel","General")

 

However, I would say better practice might be:

 

Column = IF(LEFT(DimAccount[AccountCode]) = "7", "Personnel", "General")

 

just because it makes it a bit more clear to me. Your call.

@Vvelarde You were definitely right! It was as simple as changing Account Codes to a number field. 

 

@jahida I went for your advice and incorporated the LEFT function for best practice. 

 

Thank you so much for your advice! Much appreciated. 

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.