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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
hidalgo
Regular Visitor

A ? for a Report: How to Subtract Returned Items Quantities

 

I have the following Purchasing Query that shows all rows -> purchases Receipts and Returns by Items.

I need to group by Items and sumarize the ReceiptQty. (UnitCost, ExtCost and Volume won't change)  BUT first I need to substract the Returned Items ReceiptQty (see the yellow ones)  from the Receipts Item ReceiptQty.

How do I do that in Power BI?

Thanks

Purchasing Query.png

2 ACCEPTED SOLUTIONS
kcantor
Community Champion
Community Champion

@hidalgo

In Query Editor create a conditional column for the if statement of Type.

If [Type}="Return" then [ReceiptQty]*-1 else [ReceiptQty]

Then you can group and the returns will be subtracted. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

kcantor

 

I created a conditional field as you told me called "Quantity"and it worked thanks. The returns now shows negative quantity.

let
Source = OData.Feed("------"),
#"Post Purchases_table" = Source{[Name="Post Purchases",Signature="table"]}[Data],
#"Added Conditional Column" = Table.AddColumn(#"Post Purchases_table", "Quantity", each if [Type] = "Return" then [ReceiptQty]*-1 else [ReceiptQty])
in
#"Added Conditional Column"

 

THEN. I tried to create an aditional column called "Qty" for the report  to sumarize the Quantities so it could automatically substract those Returns with negative numbers BUT The designer shows the error in the picture below.

How do I create that new Qty column to make it SUM those positive and negative Quantities?

Power BI Editor Error.png

View solution in original post

3 REPLIES 3
kcantor
Community Champion
Community Champion

@hidalgo

In Query Editor create a conditional column for the if statement of Type.

If [Type}="Return" then [ReceiptQty]*-1 else [ReceiptQty]

Then you can group and the returns will be subtracted. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




kcantor

 

I created a conditional field as you told me called "Quantity"and it worked thanks. The returns now shows negative quantity.

let
Source = OData.Feed("------"),
#"Post Purchases_table" = Source{[Name="Post Purchases",Signature="table"]}[Data],
#"Added Conditional Column" = Table.AddColumn(#"Post Purchases_table", "Quantity", each if [Type] = "Return" then [ReceiptQty]*-1 else [ReceiptQty])
in
#"Added Conditional Column"

 

THEN. I tried to create an aditional column called "Qty" for the report  to sumarize the Quantities so it could automatically substract those Returns with negative numbers BUT The designer shows the error in the picture below.

How do I create that new Qty column to make it SUM those positive and negative Quantities?

Power BI Editor Error.png

kcantor
Community Champion
Community Champion

@hidalgo

In your M code it does not appear that the conditional column for Quantity had the data type changed. By default, powerquery uses data type any. You will need to go into Query Editor and change the data type of your new conditional column to a number and then your calculation will work properly.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.