0

I have an Excel-File with some tables to calculate article-prices. In one of these tables, the user can define how to calculate a price.

For example, power query should evaluate then MIN, MAX or AVG price from a count of competitors (this is no problem and works fine). This calculated price is the initial value for further calculations. The User can enter an Operator (+, -, *, /) and an operant. enter image description here

In PQ I combine and transform the table with other tables an get and result:

enter image description here

I want to use the operator in a new calculated column, something like that:

= [Preis_MIN] [Operator] [Wert]

I know, that I can use IF()-Function(s), but if's are very slow, and at the end the table will have thousands of rows.

Is there a way to convert a TEXT in an operator? Or use

Text.Combine({Text.From([Preis_MIN]), [Operator], Text.From([Wert])}, " ") and convert the (Text) result in a formula?

1 Answer 1

1

You can use Expression.Evaluate. eg:

Expression.Evaluate(Number.ToText([Value]) & [operator] & Number.ToText([operand]))

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

This works with german decimal-notation: Expression.Evaluate(Text.Replace(Number.ToText([Value]),",",".") & [operator] & Text.Replace(Number.ToText([operant]),",","."))
@Chris Glad to help. I wonder if it might be more efficient to convert the Value and operant columns first, so as to avoid doing those steps in the Evaluate. I don't know; just wondering.
I will try both in the file, I'm with you that it would be better to convert first. But for a first solution it was perfect :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.