Hundreds of functions, right inside your macros: what’s new in NCalc Extensions
One of ReportMagic’s quiet superpowers is NCalc — the expression engine that sits behind many of our macros. Every time you write a [Calculate:] macro — or feed an expression into one of the many other macros that accept them — you’re using NCalc. And because ReportMagic builds on our open-source PanoramicData.NCalcExtensions library, every function that library adds becomes available to you in your reports.
Here’s what’s landed recently, and three different ways you can put it to work.
Fresh functions this month
The latest NCalc Extensions release brings a batch of genuinely handy additions:
titleCase— turnhello worldintoHello Worldclamp— pin a number between a minimum and maximumaverage— the mean of a list of numbersflatten— collapse nested lists into onepadRight— pad a value out to a fixed widthregexReplace— find-and-replace with the full power of regular expressionsrepeat— repeat a string N timestruncate— cut a value down to a maximum length
Plus various improvements to existing functions: a new bounds mode for substring, list support in in(), and selectable output formats for countBy.
Three ways to use them
1. In your ReportMagic macros
Drop any NCalc function straight into a [Calculate:] macro (or its shorthand, [=:). For example:
[Calculate: value="indexOf('haystack containing a needle and another needle', 'needle')"]
[Calculate: value="titleCase('quarterly network report')"]
[Calculate: value="clamp(uptimePercent, 0, 100)"]
[Calculate: value="regexReplace(hostname, '\.local$', '')"]
2. Try them live in NCalc101
Not sure how a function behaves? NCalc101 is our free online expression playground — type an expression and see the result instantly. It’s the fastest way to prototype a tricky bit of macro logic before you drop it into a report. You can organise your work into workspaces, and the file Open dialog lets you manage and reuse your saved expressions as you go.
3. Straight from the NuGet package
Building your own .NET tooling? The same functions are one install away:
PanoramicData.NCalcExtensions on NuGet
It’s open source, well tested, and the very same engine your ReportMagic macros run on — so what you prototype in code behaves identically in your reports.
Give it a go
Pick a report you maintain and look for a calculation you’ve been doing the hard way — chances are one of these new functions tidies it up. Try it live in NCalc101 first, then drop it straight into a [Calculate:] macro.
What would you like NCalc to do next? Reply and let us know…
Learn more: Calculate macro help · Try it in NCalc101 · PanoramicData.NCalcExtensions on NuGet · Magic Suite documentation