Skip to main content

Setup Excel functions

For a long time Bayes Server has supported reading data from Excel and writing data to Excel, but you can also call Bayes Server directly from Excel functions. The examples below make use of the Bayes Server .NET API and Excel-DNA.

Calling Bayes Server from an Excel function

To create Excel functions that call Bayes Server use the steps below to create and build a new C# project:

  • Create a new C# class library project in Visual Studio (e.g. 2022 Community).
  • Use NuGet to install Excel-DNA with the following command Install-Package Excel-DNA
  • Download the Bayes Server .NET API
  • Add references to the Bayes Server .NET API (e.g. all .dll files)
  • Create a new C# file called BayesServerInferenceFunctions.cs and copy the code from the Inference example into the editor.
  • Build the project. This will create a number of .xll files in the project output folder.
  • In the project output folder, double click the relevance .xll file

One the above steps have been completed a function called PredictVariable will be available in Excel.

Note that the PredictVariable function takes a 2-D array of values (columns of data) and expects a header with variable names. Using an array function allows us to perform 1000s of predictions while only loading the network once.

You can download BayesExcel.xlsx for example usage.