Search code examples
daxpowerbi-desktopdaxstudio

how to calculate the latest current week available in DAX


The code below calculates the Current Week Amt for the latest Fiscal Week num = 52 available. But it fails to calculate the latest Fiscal Week num available based on the Source File.

 Current Week Amt = 
    VAR CurrentFiscalWeek = MAX( 'DF'[Fiscal Week num] )
    RETURN
    CALCULATE(
         [total Measure],
        'DF'[Fiscal Week num] = CurrentFiscalWeek
    )

I have a dataset with different Fiscal Week num. And I would like to consider the latest Fiscal Week num as 52, 49, and 48. Is there a way to leverage this in the code ? Many thanks in advance

Source Files   Fiscal Week num
Company A       52
Company B       49
Company C       48

Solution

  • Difficult to give the answer without more info on your Dataset, however, try something like:

    Latest Week Amt = 
      var latestFiscalWeek =
        CALCULATE(
          MAX('DF'[Fiscal Week num]),
          REMOVEFILTERS('DF'[Fiscal Week num])
        )
      RETURN
        CALCULATE(
          [total Measure],
          REMOVEFILTERS('DF'[Fiscal Week num]),
          'DF'[Fiscal Week num] = latestFiscalWeek
        )