Power Fx: Open source now available
We are very excited to announce the preview release of Microsoft Power Fx as open source. Under the MIT license, you can now freely integrate this Excel-like, low code programming language in your own projects.
We announced Power Fx at Ignite in March with two blog posts, one introducing Power Fx and another going into details of the language. Both have been among the most popular of our posts this year. The interest and excitement in this new language has far exceeded our expectations.
Now we are ready to share the source code. This release is very much a preview, with a major version number of 0. We will be working hard, with your input, to solidify the language semantics and the hosting APIs. Not all the functions are implemented yet, the formula bar is not yet available, and there will be many other parts of the puzzle that I’m sure you will ask about. That’s fine, it’s a journey, and we very much look forward to taking this journey with you.
Our GitHub repo at https://github.com/microsoft/power-fx is a great place for your feedback and where we will be making future announcements.
Low code for everyone
Power Fx is the low code language for everyone. It leverages the existing knowledge of hundreds of millions of users who already know how to express logic in Excel. Natural language support with GPT-3 and no code builders that create Power Fx formulas can lower the bar even further.
Pro devs love Power Fx too because it can dramatically cut their development time. It offers a declarative, strongly typed, and functional language base. Incremental compilation, Intellisense, instant error reporting, and running while authoring provide a great authoring experience. We embrace existing tools and workflows such as VS Code and Git, today announcing experimental co-authoring support for Power Apps Studio via GitHub, Azure Dev Ops, or any other Git provider.
And best of all, their is a smooth spectrum of support between these two camps, using Power Fx as the common language. Fusion teams with a wide spectrum of skills and expertise can work together to very effectively create solutions.
Low code everywhere
Second, we implemented Dataverse formula columns. Use Power Fx to easily write concise and powerful formulas across the columns of a record:
And we are just getting started. Integrations into Power Virtual Agents and Power Automate Desktop are under way and will arrive next year.
The value proposition is clear: if someone learns Power Fx in one product, they can leverage that knowledge in another product, and another. It’s the same reason Power Fx was born in the first place, to leverage the existing knowledge of hundreds of millions of Excel users.
But why stop there. Wouldn’t the leverage of knowledge be even more powerful if it was industry wide? Successful programming languages today aren’t isolated. They find uses in scenarios we can’t even imagine yet. They need users and an active community to help them grow. This is why we are making Power Fx open source. Low code for everyone, everywhere.
Acumatica has been on this journey with us from the beginning. Early on they saw the potential and started working with us to help define the functionality and hosting APIs, providing our team with critical feedback. Ajoy Krishnamoorthy, Chief Strategy Officer & Executive Vice President at Acumatica, presented their Power Fx work at Acumatica’s Summit 2021 conference:
Our goal is to enable Acumatica, and all of you, to empower your users with low code customizations based on the well known Excel formula language. That is Power Fx.
Let’s take Power Fx out for a spin with a simple example: a Read-Eval-Print-Loop (REPL) console application where we can define formulas, work with variables, and evaluate expressions.
I’m going to use the freely available Visual Studio Community Edition for these steps to make it easy. But you don’t have to, everything here is available on GitHub as C# sources and as NuGet packages.
- If you don’t already have a copy installed of Visual Studio 2019 or later, install the Community Edition.
- Start Visual Studio. In the What would you like to do? dialog select Clone a Repository on the right hand side.
- Enter https://github.com/microsoft/power-fx-host-samples and select Clone.
- Select the ConsoleREPL solution in the Solution Explorer.
- From the Build menu, select Build Solution. This will download and install the required Power Fx NuGet packages.
- From the Debug menu select Start Debugging. A console window will pop up.
- Power Fx is running! Enter some Excel formulas and try it out.
Let’s take this step by step:
- To evaluate an expression, simply type it in. For example, 2+2. Internally within the host application’s code, a call to engine.Eval was made with the expressions string, all parsing was handled by Power Fx.
- Use the Set function to set a variable, just as it is done in Power Apps Canvas. For example, Set( Radius, 10 ) sets the Radius variable to the number 10. Internally, a call to engine.UpdateVariable was made.
- Use name = expression to define a formula. In this case, Area = 3.14 * Radius * Radius, the well known formula for the area of a circle. Internally, a call to engine.SetFormula was made.
- Since this formula has dependencies on other formulas and variables, it will be automatically recalculated when those dependencies change. As we change Radius to 400 with Set( Radius, 400 ), which calls engine.UpdateVariable internally, we see the new value for Area automatically recalculated.
- We’ll add a formula for Circumference for good measure. And then as Radius is again changed to 800, both Area and Circumference are automatically recalculated. Just like the cell dependencies of a spreadsheet.
- Evaluate Help() for information on using the REPL. The Help function is a host provided function and not part of the Power Fx language proper, a common pattern as hosts provide their own functionality. It was registered with a call to engine.AddFunction.
You can view the full source code for the Console REPL host sample at https://github.com/microsoft/power-fx-host-samples/blob/main/Samples/ConsoleREPL/ConsoleREPL.cs.
Circles are always fun, but let’s look at another example involving tables. The same filtering, sorting, and aggregating facilities that are available in Power Apps Canvas are available here:
We have implemented around 60 functions from Power Apps Canvas and Excel. We will be adding more in time.
We also have in the works a companion formula bar based on open source Monaco, the same engine powering VS Code, that we will also be providing as open source and as an npm package. It is the formula bar that can be seen in the two animations above in this blog post for commanding and formula columns. The formula bar is an integral part of the Power Fx experience, providing suggestions and immediate warning/error feedback while a maker is writing a formula. This will be coming in the months ahead, it wasn’t ready to release at this time.
Where’s the source code?
There are two GitHub repos of interest for the source code:
- https://github.com/microsoft/power-fx is the core compiler, runtime, and documentation home. There is the source for the NuGet packages.
- https://github.com/microsoft/power-fx-host-samples is the home for samples that make use of the core. It’s a great place to see how a host interacts with the engine through the hosting API.
But you don’t necessarily need to clone and build the Core. There are two NuGet packages that are used by the Console REPL: Microsoft.PowerFx.Core and Microsoft.PowerFx.Interpreter. The sources in https://github.com/microsoft/power-fx are used to create these packages.
These NuGet packages are currently hosted from a temporary location. We plan to move them to NuGet.org shortly.
What’s great is Microsoft’s own products are using the same open source offering and NuGet packages available to you. This helps us ensure the quality of the open source offering and scale up the number of products using Power Fx both inside and outside of Microsoft.
As said earlier, welcome to version 0. It’s a preview, things will be changing. It’s a starting point for iterating with all of you on the language and how it is hosted. https://github.com/microsoft/power-fx will be where the action is.