Forum Discussion

William_Moreno's avatar
6 years ago
Solved

Return null in a specific condition

Hello people,

I need help from the experts powerbi.

I have the following spreadsheet, formed by the fields: ID_PRODUCT, SALES_MONTH, QTY.

From this, I want to create two new columns:

  • FIRST SALE - column that refer to the month of first sale that occurred for a given product;
  • QTY (REVIEWED) - it is expected in the cases where the month (SALES_MONTH) is before that FIRST SALE result value equals null not zero.
ID PRODUCTSALES_MONTHQTYFIRST SALEQTY (REVIEWED)
10050010001/01/2020001/05/2020null
10050010001/02/2020001/05/2020null
10050010001/03/2020001/05/2020null
10050010001/04/2020001/05/2020null
10050010001/05/2020100001/05/20201000
10050010001/06/2020150001/05/20201500
10050010001/07/2020200001/05/20202000
10050010001/08/2020300001/05/20203000

 

Is it possible?

Thanks in advance!

 

  • William_Moreno - First will be:

     

    First = 
        MINX(FILTER('Table (27)',[ID PRODUCT]=EARLIER([ID PRODUCT]) && [SALES_MONTH]>=EARLIER([SALES_MONTH]) && [QTY]<>0),[SALES_MONTH])

     

     Reviewed

     

    Reviewed = IF([SALES_MONTH]<[First] && [QTY]=0,BLANK(),[QTY])

    PBIX attached.

     

4 Replies

  • William_Moreno ,

     

    First Sales = minx(filter(Retail, Retail[SALES_MONTH]=EARLIER(Retail[PRODUCT])),Retail[SALES_MONTH])

     

    I did not second, How can we have something before first sales?

    • William_Moreno's avatar
      William_Moreno
      Icon for Helper II rankHelper II

      Yes, you're right but, when this field is zero not null, the average is changed. Imagine if we were talking about a new product, month before that first sale it can not influence the average, Do you agree? 

      Anyway thank you for your post.

       

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

    William_Moreno - First will be:

     

    First = 
        MINX(FILTER('Table (27)',[ID PRODUCT]=EARLIER([ID PRODUCT]) && [SALES_MONTH]>=EARLIER([SALES_MONTH]) && [QTY]<>0),[SALES_MONTH])

     

     Reviewed

     

    Reviewed = IF([SALES_MONTH]<[First] && [QTY]=0,BLANK(),[QTY])

    PBIX attached.

     

    • William_Moreno's avatar
      William_Moreno
      Icon for Helper II rankHelper II

      Greg, thank you for your post.

      In my pbi archive I've changed just one signal of the function, like this:

       

       

      First = 
          MINX(FILTER('Table (27)',[ID PRODUCT]=EARLIER([ID PRODUCT]) && [SALES_MONTH]<=EARLIER([SALES_MONTH]) && [QTY]<>0),[SALES_MONTH])