Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Fill a column based on last month date

Hello!

 

I need to create a calulated column "NEW COLUM", placing the last month values acording to the  "tipe" column, 

and olny the last month f.e I had 2700000 kg of CPRS in January, i need the same value for fabruary

 

I will appreciate someone´s help

 

Thanks

 

  • Try like this:

     

    = CALCULATE(

            SUM( 'Table'[kGS] ),

            ALLEXCEPT( 'Table', 'Table'[Type] ),

            'Table'[Month] = EARLIER( 'Table'[Month] ) - 1

    )

5 Replies

  • Try like this:

     

    = CALCULATE(

            SUM( 'Table'[kGS] ),

            ALLEXCEPT( 'Table', 'Table'[Type] ),

            'Table'[Month] = EARLIER( 'Table'[Month] ) - 1

    )

    • edhans's avatar
      edhans
      Icon for Community Champion rankCommunity Champion

      Can someone explain how the post marked as a solution works? My understanding of EARLIER is it has nothing to do with dates, but with contexts within a measure.

      When I tried the measure marked as a solution, I get the following error, which is similar to what I expected.

      Calculation error in measure 'SalesData'[measure 1]: EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

      • LivioLanzo's avatar
        LivioLanzo
        Icon for Solution Sage rankSolution Sage

        edhans

         

        you're probably using it in a measure which has no row context instead of a calculated column as the OP requested:

         

        "

        Hello!

         

        I need to create a calulated column "NEW COLUM", placing the last month values acording to the  "tipe" column, 

        and olny the last month f.e I had 2700000 kg of CPRS in January, i need the same value for fabruary"

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    You'll need a date table to do this properly. Then the following measure will give you the previous month sales. The filter context of the table/matrix will keep it to just items of the same Type.

     

    =CALCULATE(
    	[Total Sales],
    	PREVIOUSMONTH('Calendar'[Date])
    )