Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Need to sum Sales, but need to flip RETURN transactions to negative before summing

For whatever reason, my company has our return sales values as a positive, so when you pull sales, your totals are high because they are the sum of sales plus the sum of returns.

 

I need to sum "COMMISSION_SALES_USD_AMOUNT" below, but I need to multiply the last 5 lines of sales by -1 so that they decrease the total rather than increase it.

 

 

DLANG_3-1595553217957.png

 

 

I need the final values and total to look like the column below on the right.

 

DLANG_2-1595553161979.png

 

Thanks in advance!!

 

 

 

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Anonymous - I'm thinking that you could use FIND or SEARCH to determine if your column contains RETURN and then flip it to negative that way.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Anonymous , Create a new column like

net sales  = if([order_line_trns_desc] ="RETURN",-1*[COMMISSION_SALES_USD_AMOUNT],[COMMISSION_SALES_USD_AMOUNT])

 

Use the exact return type text and correct column name

 

Or a measure like this

net sales  = sumx(Table, if(Table[order_line_trns_desc] ="RETURN",-1*Table[COMMISSION_SALES_USD_AMOUNT],Table[COMMISSION_SALES_USD_AMOUNT]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Thank you @amitchandak !

 

Couple pitfalls, and thank you again for your assistance as I'm new to this.

 

1 - I'm using Direct Query, so I don't believe I can create a new column

2 - The Transaction Type Description is not just RETURN or ORDER, it is a string of text such as "SALES~ORDLNS~RETURN~1068~EXTERNAL~SELF SHIP.

 

Can you help me write a measure similar to your SUMX measure that looks for the string "RETURN" rather than '...if = "RETURN"...'?

 

Also I am not fully aware of the limitations of Direct Query vs Import, is Direct Query capable of writing that type of complicated measure or is it beyond limitations?

Anonymous
Not applicable

// The fact you can't create a calc column is not a show-stopper
// but the measure will be slower than it would be if you could
// create the column. One solution is this:

[Total Amount] =
var __returnPrefix = "sales ordlns-return"
var __prefixLength = len( __prefix )
return
SUMX(
	T,
	var __isReturn = 
		left(
			T[order_line_transaction_type_desc],
			__prefixLength
		) = __returnPrefix
	var __sign = not( __isReturn ) - __isReturn
	return
		__sign * T[commission_sales_usd_amount]
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.