0

I have column for SalesAmt im my data model.

In matrix visual I have customer on the rows, and year/qtr/week on the columns.

Year values are: 2021, 2022,..

Qtr values are: Y21 Q1, Y2 Q2,...

Week values are: W1, W2,...

I've got 2 measures that I want to display in the values section of the matrix visual:

  1. Sales = sum(sales[salesamt])

  2. Last year calc:

Sales LY =

var cy=max(calendar[yr])

VAR wk=max(calendar[wk])

return calculate(sum(sales[salesamt]),removefilters(calendar),calendar[yr]=cy-1,calendar[wk]=wk)

The above works fine for cells that are under the week, but for totals of week, qtr and yr columns I get wrong value for the LY value. I know this is to do with the fact that last week is used in the DAX. How to make this universal measure that can be applied at qtr and yr level?

1 Answer 1

3
+50

Try the following:

Sales LY =
  var cy = MAX(calendar[yr])
  var wks = VALUES(calendar[wk])
  RETURN
    CALCULATE(
      [Sales],
      REMOVEFILTERS(calendar),
      calendar[yr] = cy-1 && calendar[wk] IN wks
    )
Sign up to request clarification or add additional context in comments.

8 Comments

If you see my dax, the last year value must be based on the same week number last year, and not based on dates
Understood and on re-reading your question - you need to capture all the values of wk. See above updated answer.
Nice one I will try this, didn't know I could use VALUES like this
How did it go? If all good, please Accept the answer for the benefit of all.
Sorry, English saying "6 or 2 threes" = same same but different
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.