top of page
  • MK

Export Best Practice Analyzer Results

Updated: Jun 18, 2021

Tabular Editor's Best Practice Analyzer is a fantastic tool for ensuring your tabular models abide by a set of best practice rules. In fact, I wrote a post on a collection of Best Practice Rules which can be downloaded from GitHub and immediately used to check your model. That article was followed up by an additional post which revealed more updates and new best practice rules.

There are several common ways to run the Best Practice Analyzer:

  1. Navigate to Tools -> Best Practice Analyzer.

2. Enable Best Practice Analyzer rules to run behind the scenes (File -> Preferences -> Background scan for Best Practice issues).

Once this feature is enabled you will see the number of Best Practice issues shown at the bottom of the Tabular Editor window (as shown in the screenshot below).

3. Run the Best Practice Analyzer in the Command Line (see the official documentation).

The Export Method

These 3 methods are the common methods used for running the Best Practice Analyzer. However, there is one additional method which is less well known. Thanks to Daniel Otykier, we can run a simple C# script in the Advanced Scripting window which executes the Best Practice Analyzer. The advantage of running it in this manner is that we can easily export all of the results.

using TabularEditor.BestPracticeAnalyzer;

var bpa = new Analyzer();

var sb = new System.Text.StringBuilder();
string newline = Environment.NewLine;

sb.Append("RuleCategory" + '\t' + "RuleName" + '\t' + "ObjectName" + '\t' + "ObjectType" + '\t' + "RuleSeverity" + '\t' + "HasFixExpression" + newline);

foreach (var a in bpa.AnalyzeAll().ToList())
    sb.Append(a.Rule.Category + '\t' + a.RuleName + '\t' + a.ObjectName + '\t' + a.ObjectType + '\t' + a.Rule.Severity + '\t' + a.CanFix + newline);


***Note: If you are using Tabular Editor 3, change the first line of the script above to the code shown below. This script works in Tabular Editor 3.0.6 or higher.

using TabularEditor.Shared.BPA;

Executing the script above will run all of the Best Practice Analyzer rules and output the results into a tab-delimited string (as shown below). This can easily be copied and pasted into Excel for further analysis.

An example of the Best Practice Analyzer output.


Each of the above methods for running the BPA tool has its use. I heard feedback from several folks asking for the ability to export the BPA results and now we have it! The ability to export the BPA results provides yet another great capability when using Tabular Editor and allows a new method for exploring and filtering the BPA results.

2 comentarios

Hi, doing this with regex will be very challenging. If you have a script, please post an issue on the BPA GitHub page and attach it there.


Me gusta

Rafael Barbosa
Rafael Barbosa
30 oct 2023

Is it possible to identify DAX that reference same measure many times instead using variables

example = if ([Medida1] = 5, [Medida1], [Medida2]) because it is using [Medida1] twice.

I tried to create new rule in BPA, but it works only in C# script, could you help? string Measure = "[Medida1]/[Medida5] teste 454512 [Medida3] teste teste e [Medida3]"; var pattern = @"[^[{(\]})]+(?=[[{(]|$)"; var Result = Regex.Split(Regex.Replace(Measure,pattern," ")," ").GroupBy(Value => Value).Any(group => group.Skip(1).Any()); Result.Output();

Me gusta
bottom of page