Dynamic Current vs Last Year Flag (Based on Max YearWeek)

Find the maximum YearWeek from the dataset, extract its year, and use it as the current year. Then compare each row’s year (from YearWeek) with this:

  • Same as max year → Current Year
  • One less → Last Year
  • Else → Other



Year Flag =

VAR MaxYearWeek =

    CALCULATE(

        MAX('Table'[YearWeek]),

        ALL('Table')

    )

VAR MaxYear = INT(MaxYearWeek / 100)

VAR RowYear = INT('Table'[YearWeek] / 100)


RETURN

    SWITCH(

        TRUE(),

        RowYear = MaxYear, "Current Year",

        RowYear = MaxYear - 1, "Last Year",

        "Other"

    )

Comments

Popular posts from this blog

Previous week flag

Many-to-many relationship