Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Previous Month Target

Hi everyone,

 

I've had a look around but I can't find the answer on the forums.

 

I am trying to duplicate the following measure, but change it so that it gives me the previous month to use as a target value in the KPI Visual:

 

Active Persons:
VAR mindate =
    MIN ( 'Calendar'[Date] )
VAR maxdate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( DM_PERIODS_OF_CARE ),
        ALL ( 'Calendar' ),
        OR ( DM_PERIODS_OF_CARE[END_DATE] >= mindate, ISBLANK ( DM_PERIODS_OF_CARE[END_DATE] ) ),
        DM_PERIODS_OF_CARE[START_DATE] <= maxdate
    )

 

I have tried to wrap it in 'PREVIOUSMONTH' but can't seem to get it to work. I want to have the KPI show this month's number as the indicator, and have the target be last month's number.

 

Does anyone know how I can fix this?

 

Thanks,

Dan.

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous ,

    Please create a Date table and create the below measures, then put the new measures and Date fields of Date table on visual.

    Active persons this month =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[PERSON_ID] ),
        FILTER (
            'Table',
            ISBLANK ( 'Table'[END_DATE] )
                || 'Table'[END_DATE] > MAX ( 'Date'[Date] )
        )
    )
    Active persons last month = CALCULATE([Active persons this month],PREVIOUSMONTH('Date'[Date]))
    Active persons same month last year = CALCULATE([Active persons this month],SAMEPERIODLASTYEAR('Date'[Date]))

    Best Regards

    Rena

4 Replies

  • Anonymous , Is the calendar is marked at date table? Option right click of a table .

    after that these should work

     

    Last Day = CALCULATE(COUNTROWS ( DM_PERIODS_OF_CARE ), previousmonth('Calendar'[Date]))
    last MTD Sales = CALCULATE(COUNTROWS ( DM_PERIODS_OF_CARE ),DATESMTD(dateadd('Calendar'[Date],-1,MONTH)))

     

    also check fo these resons

    Sales Date 1= [Sales Date].Date
    Sales Date 2= Date(Year([Sales Date]), Month([Sales Date]), Day([Sales Date]))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous please see above the desired result. I want the KPI to show this month's active persons and have it comparing to last month's active persons. The same logic for this month vs same month last year.

       

      The DAX code that is currently being used incorporates that the total active persons must show the persons as active in every month, not just one. Active is defined as having a START_DATE and no END_DATE, and they must be counted in each month where they have no END_DATE (for example, PERSON_ID 10 would be counted as active in Jan 09 and Feb 09)

       

      Example data:

       

       

      Thanks!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

        Please create a Date table and create the below measures, then put the new measures and Date fields of Date table on visual.

        Active persons this month =
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[PERSON_ID] ),
            FILTER (
                'Table',
                ISBLANK ( 'Table'[END_DATE] )
                    || 'Table'[END_DATE] > MAX ( 'Date'[Date] )
            )
        )
        Active persons last month = CALCULATE([Active persons this month],PREVIOUSMONTH('Date'[Date]))
        Active persons same month last year = CALCULATE([Active persons this month],SAMEPERIODLASTYEAR('Date'[Date]))

        Best Regards

        Rena