TabularEditor / BestPracticeRules

An official collection of standard Rules for use with Tabular Editor's Best Practice Analyzer.
122 stars 53 forks source link

[Rule Request] To check if "Filter' is used to filter a column in a measure #36

Open hemant1303 opened 4 years ago

hemant1303 commented 4 years ago

Hi

I need to create a rule to check whether a filter condition has been used in calculate to filter a column.

Lets say there is a fact table called Sales and it has an amount column and another column for category which has 4-5 different categories in it. Let’s say I would like to calculate sales amount for a certain category from the category column. There are 2 ways of writing a measure that filters a category column for a certain condition:-

Measure 1 = Calculate(Sum('Sales'[Amount]),'Sales'[Category]="Red") Measure 2 = Calculate(Sum('Sales'[Amount]),Filter(' Sales ', Sales '[Category]="Red"))

Both measure are correct but measure 2 takes longer time and will eventually slowdown visual rendering. As per marco russo filter function shall never be used for filtering a column. I need to create a rule that checks If any measure in the model is doing it if yes than I would like to highlight it.

Regards

m-kovalsky commented 3 years ago

This rule is available in the following Best Practice Rules. https://github.com/microsoft/Analysis-Services/tree/master/BestPracticeRules

See this rule: [DAX Expressions] Filter column values with proper syntax