cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Kasunpathirana
Resolver I
Resolver I

How to calculate only positive values in column with another column and create new column

I have column values both positive and negative for an example lets say this field is "quantity"

 

Then I have a another field lests say this is "price" I only want to multiply the positive "quanity" value with "price" and create a new column with only positive values.

3 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey,

 

due to the fact, that you want to multiply quantity * price, you have to use a table iterator, to avoid summing prices before the multiplication. In my opinion this measure is what you are looking for:

POSITIVE QUANTITY  = 
CALCULATE( SUMX('yourtable' , IF('yourtable'[quantity]>0 ,'yourtable'[quantity] * 'yourtable'[price] , BLANK()) ) )

SUMX iterates over the table, and the IF() check if the quantity is greater than zero.

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

v-yulgu-msft
Microsoft
Microsoft

Hi @Kasunpathirana,

 

You could refer to below formula to create a calculated column in source table:

POSITIVE QUANTITY =
IF ( Table[quantity] > 0, Table[quantity] * Table[price], BLANK () )

Best regards,
Yuliana Gu

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

I use a workaround for the I created a new column to take only the positive values and for the function

 

"quantity" = A-B

 

and then use the DAX code which was send by @v-yulgu-msft and @TomMartens then it's working in this scenario.

 

If there is any direct method exists rather than creating a new column. Please let me know. Thanks to @v-yulgu-msft and @TomMartens for their quick response really appreciate.

View solution in original post

4 REPLIES 4
Kasunpathirana
Resolver I
Resolver I

Thanks for the quick reply i tried the both methods.

 

But it works only if the colunmns are not calculated columns. Actually my "quantity" field is calculated and the "price" is coming from another table.

 

I tried to use but since my " quantity"column has formula "quantity" = A-B if this is the case the both functions take the A value and ignore the -B and calculate and give different figure.

 

e.g.    A= 1545 , B=2516 , quantity = (- 971) then after using both formauls it's giving me = 1545 where as I'm expecting to be 0 as the value.

 

Also please consider which DAX code should i use if the other column is from another table.

 

 

 

I use a workaround for the I created a new column to take only the positive values and for the function

 

"quantity" = A-B

 

and then use the DAX code which was send by @v-yulgu-msft and @TomMartens then it's working in this scenario.

 

If there is any direct method exists rather than creating a new column. Please let me know. Thanks to @v-yulgu-msft and @TomMartens for their quick response really appreciate.

v-yulgu-msft
Microsoft
Microsoft

Hi @Kasunpathirana,

 

You could refer to below formula to create a calculated column in source table:

POSITIVE QUANTITY =
IF ( Table[quantity] > 0, Table[quantity] * Table[price], BLANK () )

Best regards,
Yuliana Gu

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
Super User

Hey,

 

due to the fact, that you want to multiply quantity * price, you have to use a table iterator, to avoid summing prices before the multiplication. In my opinion this measure is what you are looking for:

POSITIVE QUANTITY  = 
CALCULATE( SUMX('yourtable' , IF('yourtable'[quantity]>0 ,'yourtable'[quantity] * 'yourtable'[price] , BLANK()) ) )

SUMX iterates over the table, and the IF() check if the quantity is greater than zero.

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors