Forum Discussion

mape's avatar
mape
Frequent Visitor
8 years ago

In a matrix, how I can replace values in empty cells with values of previous cells ?

Hi everyone!! I need help about this...

 

Measure of sales per year and in case there is no information for that year, show the sales of the previous year.

 

That is, given a series of sales per year for a series of customers, it would be necessary if, for a given year, that customer does not have a value, to fill the cell with the value of the last year that had value.

Example

Customer A (SALES 2017 = 1000, SALES 2016 = 1200, SALES 2015 = 900)

Client B (SALES 2016 = 500, SALES 2015 = 700)

 

In a matrix of sales of customer x year the crossing of Client B and 2017 would be empty and what I want is for it to take the value of the previous year that contains data, specifically 2016), that is to say that the table will remain as follows:

                 2015 2016 2017

Customer A 900 1200 1000

Client B 700 500 500

 

That value of 500 in 2017 I would have to put my measurement.

 

Thank you very much!!!!

 

 

11 Replies

  • Abduvali's avatar
    Abduvali
    Skilled Sharer

    Hi mape,

     

     

    You can create a Column with IF statement in it like:

     

    • COLUMN = if(YourTable[Sales] = BLANK(), 0, SUM(YourTable[SALES])
    • and then use that column for to display sales this should solve having blank cells in a matrix

     

     

    Regards

    Abduvali

    • mape's avatar
      mape
      Frequent Visitor

      Hi Abduvali, thanks for you quick response, in fact the result isn't as I expected. 

       

      By default with the field "Sales" I have this  matrix:

       

       201520162017
          
      Customer A        900,00 €    1.200,00 €    1.000,00 €
      Customer B        700,00 €        500,00 € 

       

      The new measure or calculated column that I want , it shows like this:

       

       201520162017
          
      Customer A        900,00 €    1.200,00 €    1.000,00 €
      Customer B        700,00 €        500,00 €        500,00 €

       

      i.e., if cell is blank it could show the "last sales" in the previous just period

       

      If you can give me another idea, thanks...

      :)

      • Abduvali's avatar
        Abduvali
        Skilled Sharer

        mape,

         

        That was tricky =D

         

        This should work for you just create a new column:

        • lastyear = 

          var l = SUM(Sheet6[Sales])
          var c = CALCULATE(SUM(Sheet6[Sales]),FILTER(ALLSELECTED(Sheet6[End].[Year]),Sheet6[End].[Year]-1))

          return
          if(l=BLANK(),c,l)

        Works like a charm =D

        Regards

        Abduvali