var templateDax = @"/* ----- DAX template begin ----- */

VAR yearLoic =
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( YEARS[YEAR] ),
                YEARS[YEAR] = %INTYEAR%
            )
        )
    ) = 1

VAR selection = 
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( Premium_Dev_filter[Value] ),
                Premium_Dev_filter[Value] = %selection%
            )
        )
    ) = 1

RETURN
    IF (yearLoic && selection,
            CALCULATE([Ultimate Premium], final_data[yoa_attrition] = %YEAR%),
        BLANK ()
    )



/* ----- DAX template end ----- */";

var years = new[] { "2016", "2017", "2018", "2019", "2020", "2021" };
foreach(var year in years)
{
    var measureName = "Ultimate Premium " + year;
    Selected.Table.AddMeasure(
        measureName,
        templateDax.Replace("%YEAR%",  '"'+year+'"' ).Replace("%INTYEAR%", year).Replace("%selection%","\"Ultimate Premium\"")
        
    );
}

















Example 2:
var templateDax = @"/* ----- DAX template begin ----- */

VAR yearLoic =
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( YOA_selections[Value] ),
                YOA_selections[Value] = %YEAR%
            )
        )
    ) = 1

var binder_selection = SELECTEDVALUE('Claims Per Mil Premium'[Selection])

VAR logicTest =
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( 'Claims Per Mil Premium'[Selection] ),
                'Claims Per Mil Premium'[Selection]  = binder_selection
            )
        )
    ) = 1
RETURN
    IF (
        logicTest
            && yearLoic,
            CALCULATE([Binder Average Closed CLaims], pbi_data[year_of_account] = %YEAR%, pbi_data[is_binder_market] = binder_selection),
        BLANK ()
    )



/* ----- DAX template end ----- */";

var years = new[] { "2016", "2017", "2018", "2019", "2020", "2021" };
foreach(var year in years)
{
    var measureName = "Binder Average Closed claims " + year;
    Selected.Table.AddMeasure(
        measureName,
        templateDax.Replace("%YEAR%",  '"'+year+'"' )
        
    );
}






















Example 3:
var templateDax = @"/* ----- DAX template begin ----- */

VAR yearLoic =
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( YOA_selections[Value] ),
                YOA_selections[Value] = %YEAR%
            )
        )
    ) = 1

var binder_selection = SELECTEDVALUE('Claims Per Mil Premium'[Selection])

VAR logicTest =
    COUNTROWS (
        DISTINCT (
            FILTER (
                ALLSELECTED ( 'Claims Per Mil Premium'[Selection] ),
                'Claims Per Mil Premium'[Selection]  = binder_selection
            )
        )
    ) = 1
RETURN
    IF (
        logicTest
            && yearLoic,
            CALCULATE([binders_average_clame], pbi_data[year_of_account] = %YEAR%, pbi_data[is_binder_market] = binder_selection),
        BLANK ()
    )



/* ----- DAX template end ----- */";

var years = new[] { "2016", "2017", "2018", "2019", "2020", "2021" };
foreach(var year in years)
{
    var measureName = "Binder Average Claim " + year;
    Selected.Table.AddMeasure(
        measureName,
        templateDax.Replace("%YEAR%",  '"'+year+'"' )
        
    );
}