Forum Discussion

FR_PBI's avatar
FR_PBI
Frequent Visitor
2 years ago
Solved

Need Correct DAX for an excel formula with "IF"

Hi All, can you help me with this "If" DAX?

I couldn't solve the problem.

 

 

In a generated Excel table, In column N, I have Cost which should be a multiplication of "Net Quantity" and "Product/item Cost". However, In the green highlighted cells the cost is missing. So, I need a DAX to solve this.

 

Currently, I created a column in the Excel file - Column "O" (you can see the Excel formula in the above screenshot). But I want to add a DAX for the same formula I put in column "O" which is like the below:

Cost = If "Net Quantity" * "Product/item Cost" = 0, then "Net sales" * 56% or else "Net Quantity" * "Product/item Cost".

Here I use 56% as an average cost % against sales for all other products. (if any Dax can be created for this please help me on that too If possible)

 

I need the DAX to calculate the Cost for each row individually.

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi FR_PBI ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a calculated column.

    Cost = IF([Net Quantity]*[Product/item Cost]=0,[Net Sales]*0.56,[Net Quantity]*[Product/item Cost])

    (3) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examplesIt is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi FR_PBI ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a calculated column.

    Cost = IF([Net Quantity]*[Product/item Cost]=0,[Net Sales]*0.56,[Net Quantity]*[Product/item Cost])

    (3) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examplesIt is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

  • FR_PBI's avatar
    FR_PBI
    Frequent Visitor

    Hi, Anonymous  Thank you! I have added a column with this formula. 

     

     

     

    As you can see, in the orange highlighted column (earlier cost column with blank/zero values ) now has the value in the yellow highlighted column.  Now I have a new added column in the table. 

    However, I have a question, if I don't want to add a column in the table and only want to create a measure with a DAX what can I do?

    Best Regards,