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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
MichaelK27
New Member

Power query 'Token Else Expected' error

Hi,

 

I'm relatively new to Power Query and new to this forum. I'm hoping somebody can help me with my issue.

 

I'm trying to create a custom column where I'm trying to define a (in Excel) ceiling formula, but I get an error. I don't know what I need to do, because my formula should be complete, but I can't implement it.

 

The formula I created is as follow:

if [#"Weight (kg)"] > 200 then Number.RoundUp([#"Weight (kg)"]/50,0)*50 else
if [#"Weight (kg)"] > 100 then Number.RoundUp([#"Weight (kg)"]/20,0)*20 else
if [#"Weight (kg)"] > 30 then Number.RoundUp([#"Weight (kg)"]/10,0)*10 else
if [#"Weight (kg)"] > 0 then Number.RoundUp([#"Weight (kg)"]/5,0)*5

 

This is my Excel formula:

=IF(V2="";"";IF(V2>200;CEILING(V2;50);IF(V2>100;CEILING(V2;20);IF(V2>=30;CEILING(V2;10);CEILING(V2;5)))))

 

V2 corresponds with the [#"Weight (kg)"] field.

 

Hope somebody can help me with this.

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @MichaelK27 ,

There isn't else part in the end of the formula. For each if statement, there should be then and else.

vkalyjmsft_1-1669344889940.png

If the [#"Weight (kg)"] <=0, what result do you want, directly add the result in the else part in the end.

 

Or based on the condition in your Excel formula:

This is my Excel formula:

=IF(V2="";"";IF(V2>200;CEILING(V2;50);IF(V2>100;CEILING(V2;20);IF(V2>=30;CEILING(V2;10);CEILING(V2;5)))))


I write a corresponding code:

if [#"Weight (kg)"]="" then "" else
if [#"Weight (kg)"] > 200 then Number.RoundUp([#"Weight (kg)"]/50,0)*50 else
if [#"Weight (kg)"] > 100 then Number.RoundUp([#"Weight (kg)"]/20,0)*20 else
if [#"Weight (kg)"] > 30 then Number.RoundUp([#"Weight (kg)"]/10,0)*10 else
 Number.RoundUp([#"Weight (kg)"]/5,0)*5

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @MichaelK27 ,

There isn't else part in the end of the formula. For each if statement, there should be then and else.

vkalyjmsft_1-1669344889940.png

If the [#"Weight (kg)"] <=0, what result do you want, directly add the result in the else part in the end.

 

Or based on the condition in your Excel formula:

This is my Excel formula:

=IF(V2="";"";IF(V2>200;CEILING(V2;50);IF(V2>100;CEILING(V2;20);IF(V2>=30;CEILING(V2;10);CEILING(V2;5)))))


I write a corresponding code:

if [#"Weight (kg)"]="" then "" else
if [#"Weight (kg)"] > 200 then Number.RoundUp([#"Weight (kg)"]/50,0)*50 else
if [#"Weight (kg)"] > 100 then Number.RoundUp([#"Weight (kg)"]/20,0)*20 else
if [#"Weight (kg)"] > 30 then Number.RoundUp([#"Weight (kg)"]/10,0)*10 else
 Number.RoundUp([#"Weight (kg)"]/5,0)*5

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yanjiang-msft ,

 

That makes sense. Thank you!

MichaelK27
New Member

Hi @ImkeF ,

 

The error message is this:

MichaelK27_0-1669283290306.png

 

ImkeF
Community Champion
Community Champion

Hi @MichaelK27 ,
what does the error-message say?

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors