variable
variable

Reputation: 9724

How to use calculate with field parameter?

I have 3 measures: Sales, Margin, Cost.

I have created field parameter for these 3.

Added the field parameter into table visual values section, and client name is on rows section.

There is a slicer that allows me to control the table visual values to be either sales, margin or cost.

I want to create a calculated measure based on this field paramter that will show me previous year value. So I tried CALCULATE(FP, DateAdd('Datetbl'[Date],-365,DAY)

This doesn't work. I also tried CALCULATE(MAX(FP[FP]), DateAdd('Datetbl'[Date],-365,DAY)

Upvotes: 0

Views: 888

Answers (1)

Sam Nseir
Sam Nseir

Reputation: 12111

Unfortunately, you cannot use Field Parameters directly in calculations.

You'll have to have something like this:

FP PrevYear =
  var pyDates = DateAdd('Datetbl'[Date], -1, YEAR)
  return SWITCH( MIN(FP[FP Fields]),
    NAMEOF([Sales Measure]), CALCULATE([Sales Measure], pyDates),
    NAMEOF([Margin Measure]), CALCULATE([Margin Measure], pyDates),
    NAMEOF([Cost Measure]), CALCULATE([Cost Measure], pyDates)
  )

You may also want to look at Calculation Groups:

Upvotes: 0

Related Questions