0
votes

My question might be simple but I've been stuck here for a while.

I'm trying to get the values for current month and previous month. I created 2 Measures to do that (CurrentVal and PreviousVal).

My DAX measures are:

CurrentVal = SUM ( Database[KPI_Value] )

PreviousVal = 
    CALCULATE ( 
        [CurrentVal]; 
        PREVIOUSMONTH ( DIM_Date[Date] )
    )

In the image below, when displayed as a table, you can see it's working fine.

enter image description here

However, I don't want a table like that, but instead I want a slicer where the user can select the month and he will be able to see the current and previous month values, just like the image below.

The problem, as you can see, is that when I remove the Date from the table and include the slicer, the PreviousVal returns always blank (in this example, it should return 0,44). What am I doing wrong here?

enter image description here

Thanks in advance!

1

1 Answers

3
votes

What you have set up will work, assuming:

  1. You have a relationship between the Date fields in the Database and DIM_Date tables
  2. Table DIM_Date is marked as a date table (Table view, Modelling tab, Mark as Date Table )

Here's a worked example: https://excel.solutions/so20181121_previousmonth/