Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Comparing a Column with Strings with a specific Value

Good Morning,

 

i am new to PowerBi and i want to adopt an Excel formula to PowerBi.

The formula in Excel is as follows:

=IF(M2="R4";I2;IF(M2="R3";J2;IF(M2="R2";K2;IF(M2="R1";L2))))

and here a picture of the table:

My question is how do i convert this formula to DAX, because i want an extra column (in Excel Column N) that is showing the specific value of the cell with regard to whether the row belongs to R1,R2,R3 or R4

My attempt looks like this, but an error is always returned:

Price = IF(('123'[Pricelist])="R1";SUM('456'[R1_Price]);IF(('123'[Pricelist])="R2";SUM('456'[R2_Price]);IF(('123'[Pricelist])="R3";SUM('456'[R3_Price]);IF(('123'[Pricelist])="R4";SUM('456'[R4_Price]);"0"))))

I hope somebody can help me.

 

Thanks a lot

Greetings Lukas

 

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hey davehus,

      thank you for your reply.

      I dont use Power Query. In the past, I exported the raw Power Bi data to Excel and then adjusted it there. Now I want to store the required calculations directly in Power Bi, which come from SAP. Or am I missing something? 

       

       

      • davehus's avatar
        davehus
        Memorable Member

        Hi Anonymous ,

         

        You do use powerquery, you just may not have noticed. 🙂 It is the editor that is used when you click transofrm data in powerbi. Once you import your data, go to transform in the powerquery editor and select conditional column, you can use it to build an if statement based on your needs and select a column rather than a value to get data from each column based on the price. 

         

        Hope this helps