Table of Contents

Code action RW001 (Rewrites) Rewrite TOTALxTD using CALCULATE

Description

Functions such as TOTALMTD, TOTALQTD and TOTALYTD can be rewritten using the CALCULATE function.

Example

Change:

 TOTALYTD([Total Sales], 'Date'[Date])

To:

CALCULATE([Total Sales], DATESYTD('Date'[Date]))

Why is Tabular Editor suggesting this?

This rewrite is useful in case you want to add additional filters or modify the calculation context.

Note

This code action is in the Rewrites category, which means that it does not represent a general recommendation or best practice. Instead, the code action provides a quick way to rewrite the code in a different way, for example as part of a larger refactoring. After applying the code action and until further edits are made, you may see an Improvement or Readability code action that suggests to modify the code back to its original state.