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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
bkwohls
Helper I
Helper I

Calculation associated Order Totals by Campaign

In my data, sales orders are recorded at the line level. At each sales order line there is a campaign code to identify various attributes. I can SUM the lines by campaign code without any trouble at all. What I have been asked to provide is the Sum of the orders in which ANY of the sales order lines contain the campaign code. In the sample data below, the campaign code RZZDTA exists in only orders 1 & 2.  I would like the calculation to give me the SUM of orers 1& 2  not just the sum of the order lines. The Desired result is the column labeled AssociatedOrderSum below. Likewise the CUST code shows up in all orders and should be the SUM of all order lines. At the very bottom is the formula I have been working on with no luck. It is based on the closest thing I could find.

Thanks in advance.

SAMPLE DATA:

OrderNumOrderLineTotalLineValueCampaign
11$1,265.56CUST
12$407.94CUST
13$1,816.92CUST
14$1,355.88CUST
15$1,477.98CUST
16$1,613.58CUST
17$1,559.76CUST
18$1,644.00CUST
19$294.99CUST
110$1,019.04CUST
111$2,909.94CUST
112$1,663.65CUST
114$660.00CUST
115$5.00RZZDTA
21$15.21CUST
22$0.00CUST
23$98.76CUST
24$1,055.12CUST
25$32.01CUST
26$0.89CUST
27$7.88CUST
28$597.99RZZDTA
31$55.50CUST
32$654.23CUST
33$98.74CUST
34$1,008.56CUST
41$899.99PJ99
42$7.84PJ99
43$0.50CUST

 

Desired Result:

CampaignCampaignSumAssociatedOrderSum
CUST $       20,716.64 $                     22,227.46
RZZDTA $             602.99 $                     19,502.10
PJ99 $             907.83 $                           908.33

 

DAX Attempt:

 

Campaign Orders all = 
VAR EventVals_ = Values(MKGT_CAMP[Campaign ID])
VAR OrderList_ =
  CALCULATETABLE(
  	VALUES(Orders[OrderNum]),
  	MKGT_EVENT[Campaign ID] = EventVals_)   
Return
CALCULATE(sum(Orders[TotalLineValue]),filter(Orders,Orders[OrderNum] in OrderList_))

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @bkwohls 

Please check the below picture, measure, and the sample pbix file's link, whether it is what you are looking for.

 

Picture4.png

 

AssociatedOrderSum =
VAR currentcampaign =
SELECTEDVALUE ( Orders[Campaign] )
VAR newtable =
SUMMARIZE (
FILTER ( ALLSELECTED ( Orders ), Orders[Campaign] = currentcampaign ),
Orders[OrderNum]
)
RETURN
CALCULATE (
[CampaignSum],
FILTER ( ALLSELECTED ( Orders ), Orders[OrderNum] IN newtable )
)
 
 
 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here and Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @bkwohls 

Please check the below picture, measure, and the sample pbix file's link, whether it is what you are looking for.

 

Picture4.png

 

AssociatedOrderSum =
VAR currentcampaign =
SELECTEDVALUE ( Orders[Campaign] )
VAR newtable =
SUMMARIZE (
FILTER ( ALLSELECTED ( Orders ), Orders[Campaign] = currentcampaign ),
Orders[OrderNum]
)
RETURN
CALCULATE (
[CampaignSum],
FILTER ( ALLSELECTED ( Orders ), Orders[OrderNum] IN newtable )
)
 
 
 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here and Go to My LinkedIn Page


PERFECT thank you. I will try and learn from your DAX and see what I was doing wrong. I think I missed the ALL filters.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors