This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
Trying to do what I figured was a simple nested if statement in power query. Use the 'add custom column' function to build this quickly.
The resultant M formula is:
= Table.AddColumn(#"Reordered Columns", "Grade", each if [Grade Original] = "Prep" then 0 else if Text.Start([Grade Original],1) = "7" then 7 else -1)
As you can see in the above, the first evaluation of the if statement works, as does the else if. It's falling over at the else statement which I thought would be pretty simple (I actually want to return the [Original Grade] column as the else but simplified it to debug.
It doesn't matter what value I try and put in the 'else' statement (tried a string, number, null), it throws the same error (below). Can't for the life of me work out what the issue is but it would be great if someone could provide some insight.
If it matters, I'm using power query in Excel and have the latest office 365 release. I've tried searching for similar errors but can't find anything that works.
Thanks in advance.
Solved! Go to Solution.
The datatype for the rows that are failing are numbers so the expression Text.Start([Grade Original],1) is returning the error. Either change the column type to text prior to adding the column or modify the formula as show below:
= Table.AddColumn(#"Reordered Columns", "Grade", each if [Grade Original] = "Prep" then 0 else if Text.Start(Text.From([Grade Original]),1) = "7" then 7 else -1)
The datatype for the rows that are failing are numbers so the expression Text.Start([Grade Original],1) is returning the error. Either change the column type to text prior to adding the column or modify the formula as show below:
= Table.AddColumn(#"Reordered Columns", "Grade", each if [Grade Original] = "Prep" then 0 else if Text.Start(Text.From([Grade Original]),1) = "7" then 7 else -1)
Thank you! Yes that was the solution. I hadn't even looked at that part of the formula as it was evaluating correctly for the condition I wanted. Makes total sense now that I have been enlightened.
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.