You will need tabular editor for this to work , so google tabular editor and download it form their github repo.
this is the syntax:
var templateDax = @"/* ----- DAX template begin ----- */ VAR logicTest = COUNTROWS(DISTINCT(FILTER(ALLSELECTED(YEARS[YEAR]), YEARS[YEAR] = %YEAR% ))) = 1 /* TODO - Add remaining DAX code here */ /* ----- DAX template end ----- */"; var years = new[] { "2010", "2011", "2012", /* ...etc... */ "2020" }; foreach(var year in years) { var measureName = "measure_" + year; Selected.Table.AddMeasure( measureName, templateDax.Replace("%YEAR%", year) ); }