Forum Discussion
Conditional measure to calculate
Hello,
I am trying to add a measure based on condition.
If the Weight/Box=Default then the Total Boxes Ordered = Order
If the Weight/Box is NOT DEFAULT, then the Total Boxes Ordered = Order divided by Weight per Box.
Thanks.
Hey Oros ,
if you want to do it in Power Query then add a "Custom Color" and add the following formula:
if [Weight_Box] = "Default" then [Order] else [Order] / [Weight_Box]If you want to solve that in the data model as calculated column try the following formula:
Total Boxes Ordered = IF( myTable[Weight_Box] = "Default", myTable[Order], DIVIDE( myTable[Order], myTable[Weight_Box] ) )If you need any help please let me know.If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍Best regardsDenisBlog: WhatTheFact.biFollow me: twitter.com/DenSelimovic
13 Replies
- selimovd
Most Valuable Professional
Hey Oros ,
if you want to do it in Power Query then add a "Custom Color" and add the following formula:
if [Weight_Box] = "Default" then [Order] else [Order] / [Weight_Box]If you want to solve that in the data model as calculated column try the following formula:
Total Boxes Ordered = IF( myTable[Weight_Box] = "Default", myTable[Order], DIVIDE( myTable[Order], myTable[Weight_Box] ) )If you need any help please let me know.If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍Best regardsDenisBlog: WhatTheFact.biFollow me: twitter.com/DenSelimovic - parry2k
Super User
Oros try this in DAX using calculated columns
Total Boxes Ordered = IF ( YourTable[Weight/Box] = "Default", YourTable[Order], DIVIDE ( YourTable[Order], VALUE ( YourTable[Weight/Box] ) )The reason you want to use VALUE in divide because your Weight/Box column is of Text type and we need to convert it into value. Read mode about value function here VALUE function (DAX) - DAX | Microsoft Docs
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- Oros
Post Prodigy
- Oros
Post Prodigy
Hi parry2k ,
I am adding a column. I do not mind if the solution can be for a measure. Thanks.
Here is the error:
DAX comparison operations do not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.