cancel
Showing results 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

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.

SAMPLE DATA:

 OrderNum OrderLine TotalLineValue Campaign 1 1 \$1,265.56 CUST 1 2 \$407.94 CUST 1 3 \$1,816.92 CUST 1 4 \$1,355.88 CUST 1 5 \$1,477.98 CUST 1 6 \$1,613.58 CUST 1 7 \$1,559.76 CUST 1 8 \$1,644.00 CUST 1 9 \$294.99 CUST 1 10 \$1,019.04 CUST 1 11 \$2,909.94 CUST 1 12 \$1,663.65 CUST 1 14 \$660.00 CUST 1 15 \$5.00 RZZDTA 2 1 \$15.21 CUST 2 2 \$0.00 CUST 2 3 \$98.76 CUST 2 4 \$1,055.12 CUST 2 5 \$32.01 CUST 2 6 \$0.89 CUST 2 7 \$7.88 CUST 2 8 \$597.99 RZZDTA 3 1 \$55.50 CUST 3 2 \$654.23 CUST 3 3 \$98.74 CUST 3 4 \$1,008.56 CUST 4 1 \$899.99 PJ99 4 2 \$7.84 PJ99 4 3 \$0.50 CUST

Desired Result:

 Campaign CampaignSum AssociatedOrderSum 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
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.

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.

2 REPLIES 2
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.

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.

Helper I

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.

Announcements

#### Power BI Monthly Update - July 2024

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

#### 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
Top Kudoed Authors