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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
ryan_b_123
Frequent Visitor

Using value from column to affect calculation in Power Query

Col 1Col 2Col 3Desired Result
4+59
3-21

 

Let's say I have above dataset:

To do above, I could write a formula in Power QUery something like "if [col 2] = "+" then [Col 1] + [Col 3] else [Col 1] - [Col 3].  I DO NOT want this sort of solution.

 

Instead, I would like the value of [Col 2] to be inherent within the formula.  Perhaps with some 'mythical' formula like below:

[Col 1]    MadeUpFunction[Col 2]    [Col 3]

 

Is there any sort of way to affect the Power Query code using a field in your dataset?

1 ACCEPTED SOLUTION
HotChilli
Community Champion
Community Champion

Yes, there is a way.

Use Expression.Evaluate

You can build a string from the first 3 columns ( either by appending with & or use Text.Combine and then just pass that to Expression.Evaluate()

View solution in original post

4 REPLIES 4
ryan_b_123
Frequent Visitor

Thank you, so much.  This is exactly what I am looking for.  I am curious about one thing though.

Expression.Evaluate(Text.Combine({"5","=","5"}, " "))   will return true.  Which is good.

Expression.Evaluate(Text.Combine({"hello","=","hello"}, " "))   will return an error.  "The name 'hello' doesn't exist in the current context."

 

Do you know why we cannot use "=" operator for alphabetical comparisons? 

There's nothing wrong with the "="
See the 3rd example
https://learn.microsoft.com/en-us/powerquery-m/expression-constant#example-3 

You need Expression.Constant

Thanks for the reply, but could you be a bit more specific how Expression.Constant is used?  Is this wrapped inside of the Expression.Evaluate?

 

The documenation is extremely short on this function and I do not know what it does exactly.

HotChilli
Community Champion
Community Champion

Yes, there is a way.

Use Expression.Evaluate

You can build a string from the first 3 columns ( either by appending with & or use Text.Combine and then just pass that to Expression.Evaluate()

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors