question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for simple arithmetic on fields?

See original GitHub issue

I love this library and the love that’s gone into writing and maintaining it!

Has anyone ever suggested adding support for simple arithmetic expressions for numeric fields with field value source, so that we could express rules like Price < 1.05 * YesterdayPrice (where Price and YesterdayPrice are both numeric fields)?

I’m currently interested in linear scaling (a * Field) but no doubt others may be interested in additive (b + Field) and affine (a * Field + b) transforms, for constants a and b that the user specifies in Query Builder (you might decide to limit the complexity of these transforms the library supports).

I can very well imagine writing a custom ValueEditor which renders an input for the constants and a dropdown for the field selector, but how would that be represented in RuleType, and how much work would it be to export that in SQL/CEL?

(Ideally this would also support between/notBetween (per discussion in issue 215), so we could have rules like Price BETWEEN BestBid * 0.99 AND BestAsk * 1.01, though this isn’t critical since users can always convert between to a rule group consisting of two rules.)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jakeboone02commented, Jun 5, 2022

By the way, I just put up PR #320 to add a parseJsonLogic function that converts JsonLogic objects to RQB’s RuleGroupType.

0reactions
jakeboone02commented, Jun 21, 2022

Great! I’m glad that worked out. I’ve even got my own use cases for transformQuery at work so it was good to get that added.

Since you’re clearly an advanced user and really seem to “get” the library, I would encourage you to submit any ideas you may have for the Tips & Tricks pages. The tracking issue on the docs repo has some yet-to-be-documented ideas: react-querybuilder/react-querybuilder.github.io#2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Math Formula Field - For Simple Mathematical Calculations
The Math Formula field supports simple mathematical formulas for addition, subtraction, multiplication and division. Use field labels as merge values to build ...
Read more >
Doing Basic Maths on Numeric Fields via Calculated Fields
Note: Google Data Studio is now known as Looker Studio. Follow the steps below to do basic maths on numeric fields via calculated...
Read more >
About calculated fields - Looker Studio Help
Calculated fields can perform arithmetic and math, manipulate text, date, and geographic information, and use branching logic to evaluate your data and return ......
Read more >
Simple math calculations from field value?
ACF has a plugin called “Calculated fields for ACF”. Does Pods have an easy way to perform simple math from values entered in...
Read more >
RPG/400 Help - Arithmetic Operations
Arithmetic operations can be done only on numeric fields (including numeric subfields, numeric arrays, numeric array elements, numeric table elements, numeric ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found