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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
majdkaid22
Helper V
Helper V

custom column in M query

Hi guys, 

 

Am using the below formula to filter a particular column based on the last character in the group name 

 

if Text.End( Text.Upper( [Group] ), "S" )
then "A"
else "B"

 

it's returning with error

 

(Expression.Error: We cannot convert the value "S" to type Number.


Details:
Value=S
Type=Type

 

S or B.PNG

 

 

What does need to be fixed?

 

Thanks,

M

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

try this:

 

if Text.End( Text.Upper( [Group] ), 1) = "S"
then "A"
else "B"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Super User
Super User

try this:

 

if Text.End( Text.Upper( [Group] ), 1) = "S"
then "A"
else "B"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

thanks @ImkeF 

 

for me personal knowledge, why the ,1 made the difference? the goup column is text, hence I thought what I did was right

 

Thanks mate

Majd

This is a syntax-error in the Text.End-formula (second argument need to be the number of letters to be returned - LinkToRessource) as well as in the conditional statment (when you use an if you need to combine it with an operator/comparer - LinkToRessource).

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

KHorseman
Community Champion
Community Champion

Text.End will return the last n characters of a string. You have to tell it how many you want. If you leave off that number it will give you an error because you didn't finish writing the entire formula. Text.End( Text.Upper( [Group] ), 1) returns the last character. Text.End( Text.Upper( [Group] ), 2) would return the last 2 characters, Text.End( Text.Upper( [Group] ), 7) the last 7 characters, etc.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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