Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions Basic/Format All Measures.csx
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
/*
* Title: Format All Measures
* Title: Format All Measures
*
* Author: Matt Allington, https://exceleratorbi.com.au
* Authors: Matt Allington, https://exceleratorbi.com.au
* trjohnson19, https://github.com/trjohnson19
*
* This script loops through all the measures in your model and calls out to daxformatter.com
* in order to format them.
* This script loops through the measures in the model and queries daxformatter.com
* to format the measures in a batch process.
*
* CAUTION: If your model has many measures (> 100) please use with care, as this will perform
* many requests against the www.daxformatter.com web service. It will take some time to run,
* and also, we don't want to DDoS attack daxformatter.com :-)
* This script uses the `FormatDax` overloaded extension method introduced in TE2 2.13.0.
* FormatDax deprecation notice: https://docs.tabulareditor.com/te2/FormatDax.html.
*/

//Format All Measures
foreach (var m in Model.AllMeasures)
{
m.Expression = FormatDax(m.Expression);
/* Cycle over all measures in model and format
them all using DAX Formatter */
/* Format either all measures or selected measures. */
var _measures = Model.AllMeasures;
//var _measures = Selected.Measures;

/* Format all measures using default long lines and with a space after the function name. */
_measures.FormatDax();

/*
* Alternative method to customize formatting returned.
* `FormatDax(this IEnumerable<IDaxDependantObject> objects, bool shortFormat = false, bool? skipSpaceAfterFunctionName = null)`
*/
//_measures.FormatDax(false, null);

/*
* Ensure measure text has a leading newline.
* Fixes issue of measure expression starting directly after `<measure name> = ` on line 1.
*/
foreach (var _m in _measures) {
_m.Expression = "\n" + _m.Expression
}

/*
* Deprecated `FormatDax` method for use in TE2 < 2.13.
*
* foreach (var _m in _measures) {
* _m.Expression = FormatDax(_m.Expression);
* }
*/