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
Jungbin
Frequent Visitor

SUMX? CALCULATE? Sum with Conditions and Return Same Value by Each Opportunity

Hi all

 

I'd like to sum numbers with some conditions and to return that summarized number by each sales opportunity in my table.

 

For instance, I'll only sum opportunities that meet below conditions:

  1. Product = TEST
  2. Category = Negotiation, Closing
  3. Period = Q4

I want a new column to be made as 'Summarized Number' in the table below. 

Can anyone help me how to solve this? I've failed with SUMX and CALCULATE...

 

Opportunity ID       Product    Amount   CategoryPeriod     (Column I Want) Summarized Number
AAATEST$12,000NegotiationQ4$12,000
AAAMulti$5,000NegotiationQ4$12,000
AAAOther$10,000NegotiationQ4$12,000
BBBMulti$6,000ClosingQ4$0
BBBOther$2,500ClosingQ4$0
CCCTEST$8,000ProposalQ4$0
DDDMulti$7,500NegotiationQ1$0
DDDTEST$3,000NegotiationQ1$0
1 ACCEPTED SOLUTION
Prateek97
Resolver III
Resolver III

Hi @Jungbin ,

 

Pleasae try the below code.

 

New Column = 

CALCULATE(SUM('Table'[Amount]),ALLEXCEPT('Table','Table'[Opportunity ID]),'Table'[Product]="TEST", 'Table'[Category] in {"Negotiation","Closing"},'Table'[Period]="Q4")

 

If it works, please mark this as the solution.

 

Thanks

View solution in original post

10 REPLIES 10
Prateek97
Resolver III
Resolver III

Hi @Jungbin ,

 

Pleasae try the below code.

 

New Column = 

CALCULATE(SUM('Table'[Amount]),ALLEXCEPT('Table','Table'[Opportunity ID]),'Table'[Product]="TEST", 'Table'[Category] in {"Negotiation","Closing"},'Table'[Period]="Q4")

 

If it works, please mark this as the solution.

 

Thanks

Hi Prateek97

 

Thanks for your help.

Could you please check your DAX once again? It returns me below error message:

 

The ALLEXCEPT function expects a table reference expression for argument '3', but a string or numeric expression was used.

Hi @Jungbin ,

 

Can you please send the DAX you have written here.

Hi @Jungbin ,

 

Please close the bracket after Opportunity ID highlighted in Red.

 

Try = CALCULATE ( SUM ( 'Table' [Amount] ), ALLEXCEPT ( 'Table' , 'Table' [Opportunity ID]), 'Table' [Product] = "TEST" , 'Table' [Category] in { "Closing" , "Negotiation" }, 'Table' [Period] = "Q4" ))

Thank you so much, Prateek97! 😁

Ritaf1983
Super User
Super User

Hi @Jungbin 
If I understood you right and you need this calculation row by row you can try this 2 measures :
1. 

Total Amount = SUMX('Table','Table'[Amount])
2. 
test = CALCULATE(
    [Total Amount],FILTER('Table',
    'Table'[Product]="TEST" &&'Table'[Category] in{ "Negotiation"," Closing" } && 'Table'[Period]="Q4"))
Ritaf1983_0-1692615656693.png

I changed 1 of the rows to have one more row that meets the conditions to insure my formula is working.

If you need other results please give more details and show a desired result

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Hi Ritaf1983!

 

Thanks for your help.

From your screenshot, I want $12,000 is also filled out in the first and second row in 'test' column.

I think @Prateek97  suggested the right solution...

Semaj06
Regular Visitor

HI,

 

Calculate(sum(Summarized Number),

[IDPRODUCT]="TEST"

&&[Category] in{"closing","negociation"}

&&[Period]="Q4")

 

Hi Semaj06!

 

Thanks for your reply.

I think there is a misunderstanding, so I edited my post. 

Summarized Number is a new column I want. So, it can't be used in Calculate.

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.