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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.