Forum Discussion

manojk_pbi's avatar
manojk_pbi
Helper V
1 year ago
Solved

Current month vs previous month comparison in table

Hello,

 

I have single table with facts and dimensions data. I need to have table to show the kpis of projects for the current month and also the previous month along with indicators.

I am not getting how we can get the previous months kpi data along with current month when reporting month selected for current by user.

 

Attaching the sample data for referecne

PRJ NameDivisionBU UNITReportingDateKPI
PRJ1DIV1BU125-Jun60%
PRJ2DIV1BU125-Jun85%
PRJ3DIV1BU225-Jun79%
PRJ4DIV1BU325-Jun93%
PRJ5DIV1BU125-Jun85%
PRJ6DIV2BU125-Jun85%
PRJ7DIV2BU125-Jun60%
PRJ8DIV2BU325-Jun60%
PRJ1DIV1BU125-Jul85%
PRJ2DIV1BU125-Jul60%
PRJ3DIV1BU225-Jul60%
PRJ4DIV1BU325-Jul60%
PRJ5DIV1BU125-Jul60%
PRJ6DIV2BU125-Jul60%
PRJ7DIV2BU125-Jul85%
PRJ8DIV2BU325-Jul43%

Expected output: - Comparison is diff of Curr vs Prev

 

  • Hi manojk_pbi

    Can you please try the below steps to get your result ?

    1. Create dim date table table and in that create a calculated column.

    YearMonth = FORMAT(Dim_Date[Date], "YYYYMM")

     


    2. Create three measure using below dax.

     

    KPI_CurrMonth =
    VAR SelectedMonth = MAX ( 'Dim_Date'[Date] )
    RETURN
    CALCULATE (
        AVERAGE ( 'Table'[KPI] ),
        FILTER (
            ALL ( 'Dim_Date' ),
            'Dim_Date'[YearMonth] = FORMAT ( SelectedMonth, "YYYYMM" )
        )
    )
     
    ---------------------------------------------------------------------------------------------------- 
     
    KPI_PrevMonth =
    VAR SelectedMonth = MAX ( 'Dim_Date'[Date] )
    RETURN
    CALCULATE (
        AVERAGE ( 'Table'[KPI] ),
        FILTER (
            ALL ( 'Dim_Date' ),
            'Dim_Date'[YearMonth] =
                FORMAT ( EOMONTH ( SelectedMonth, -1 ), "YYYYMM" )
        )
    )

     

     

     

    ------------------------------------------------------------------------------------

     

    KPI_Comparison =
    [KPI_CurrMonth] - [KPI_PrevMonth]
     
     
    --------------------------------------------------------------------------------------
     
     
    For the icon 
     
    Click on chart then go for the conditinal formatting for KPI_Comparison

     

     

    Result

     

    If this answers your questions, kindly accept it as a solution and give kudos.

  • Hi manojk_pbi 

    Create measure using below dax.


    KPI_Comparison_1 =
    IF (
        NOT ISBLANK ( [KPI_PrevMonth] ),
        [KPI_CurrMonth] - [KPI_PrevMonth]
    )
     

    Case1. when PreMth value is there

     

    Case 2. If PrevMth values is not there

     

    If this answers your questions, kindly accept it as a solution and give kudos.

7 Replies

  • Hi manojk_pbi

    Can you please try the below steps to get your result ?

    1. Create dim date table table and in that create a calculated column.

    YearMonth = FORMAT(Dim_Date[Date], "YYYYMM")

     


    2. Create three measure using below dax.

     

    KPI_CurrMonth =
    VAR SelectedMonth = MAX ( 'Dim_Date'[Date] )
    RETURN
    CALCULATE (
        AVERAGE ( 'Table'[KPI] ),
        FILTER (
            ALL ( 'Dim_Date' ),
            'Dim_Date'[YearMonth] = FORMAT ( SelectedMonth, "YYYYMM" )
        )
    )
     
    ---------------------------------------------------------------------------------------------------- 
     
    KPI_PrevMonth =
    VAR SelectedMonth = MAX ( 'Dim_Date'[Date] )
    RETURN
    CALCULATE (
        AVERAGE ( 'Table'[KPI] ),
        FILTER (
            ALL ( 'Dim_Date' ),
            'Dim_Date'[YearMonth] =
                FORMAT ( EOMONTH ( SelectedMonth, -1 ), "YYYYMM" )
        )
    )

     

     

     

    ------------------------------------------------------------------------------------

     

    KPI_Comparison =
    [KPI_CurrMonth] - [KPI_PrevMonth]
     
     
    --------------------------------------------------------------------------------------
     
     
    For the icon 
     
    Click on chart then go for the conditinal formatting for KPI_Comparison

     

     

    Result

     

    If this answers your questions, kindly accept it as a solution and give kudos.

    • manojk_pbi's avatar
      manojk_pbi
      Helper V

      Hello mdaatifraza5556 , thanks lot for your quick reply and the solution. Great !!.

       

      I have one question, do we need to have separate Date table why cann't we use the date from the same table ? 

      • mdaatifraza5556's avatar
        mdaatifraza5556
        Super User

        Hi manojk_pbi 

        It will also work, but it is a best practice to create a separate Date table.
        In some cases, especially when using time intelligence functions it works more reliably and ensures proper results.

         

         

         

        If this answers your questions, kindly accept it as a solution and give kudos.

    • manojk_pbi's avatar
      manojk_pbi
      Helper V

      How can we modify the KPI Comparison,  not to show anything in comparison and no arrows when prev is not present.

      • mdaatifraza5556's avatar
        mdaatifraza5556
        Super User

        Hi manojk_pbi 

        Create measure using below dax.


        KPI_Comparison_1 =
        IF (
            NOT ISBLANK ( [KPI_PrevMonth] ),
            [KPI_CurrMonth] - [KPI_PrevMonth]
        )
         

        Case1. when PreMth value is there

         

        Case 2. If PrevMth values is not there

         

        If this answers your questions, kindly accept it as a solution and give kudos.