Forum Discussion

Domien's avatar
Domien
Regular Visitor
2 years ago
Solved

Content from a previous row

Hi,

 

I want to make new column in which I want to put the content of an existing colomn "A" or the content from the previous row of the new colom depending on the content of column "A".

 

In Excel I can use this formula: IF(left(A2;1)="-";C1;B2)

 

 I've tried several options (even chat GPT) but it won't work.

 

Kind regards,

Domien

7 Replies

  • Domien Hello,
    you can refer this dax.
     Create a column then create the same measure and replace the result and alternate result column.

    New column = IF(Sheet1[Product]= BLANK(), Expected result column, alternate result column )


    Thanks
    Harish M
    • HarishKM's avatar
      HarishKM
      Super User

      Domien Hello,
      I meant this.

      Color = IF(Sheet1[Product]= BLANK(), Sheet1[Product_new] )

      I mean Instead of product new you can use B column.

      Thanks
      Harish M
    • Domien's avatar
      Domien
      Regular Visitor

      Hi Harish,

      I'm sorry but I don't know what you mean 

    • Domien's avatar
      Domien
      Regular Visitor

      Thanks!. This works perfect for me!!

  • 123abc's avatar
    123abc
    Community Champion

    In Power Query, you can create a new column that depends on the content of an existing column "A" or the content from the previous row of the new column based on the content of column "A." You can achieve this using the following steps:

    1. Open Power Query Editor in Power BI or Excel.

    2. Select your table that contains column "A."

    3. Go to the "Add Column" tab and click on "Custom Column."

    4. In the "Custom Column" dialog box, enter a name for the new column (e.g., "NewColumn").

    5. In the "Custom column formula" box, enter the following formula:

    if Text.Start([A], 1) = "-" then [NewColumn]{[Index]-1} else [A]

     

    This formula checks if the first character of column "A" is "-", and if it is, it retrieves the value from the previous row of the "NewColumn"; otherwise, it takes the value from column "A."

    1. Click the "OK" button to create the new column.

    This will create a new column "NewColumn" that meets your specified conditions. If the first character of column "A" is "-", it will take the value from the previous row of "NewColumn"; otherwise, it will take the value from column "A."

  • Domien's avatar
    Domien
    Regular Visitor

    Thanks, for the quick reply.

     

    I've tried something simular but when I use your solution I get errors whent the first character is an "-"

     

    I've used this formula. I've checked the column names so that could not be the problem