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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
auron
New Member

SUM function with multiple condition

Dear all, i have a table like this one:

idpricerequested
123150TRUE
123150TRUE
456100TRUE
456100TRUE
789200TRUE
789200TRUE
484350TRUE
159280TRUE
753420FALSE
   
Total150+100+200+350+280
 1080 

 

What i need is a DAX query to calculate a new measure for the sum of the column price based on these conditions:

  • Row must have value "true" for column "requested"
  • I have multiple rows with same ids, i need to consider only once rows with the same ID (distinct ids)

The total should be calculated like this:
Total = 150 (id:123) + 100(id:456) + 200 (id:789) + 350 (id:484) + 280 (id:159)

 

Can you please help me? Thanks a lot

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @auron ,

 

Try the following code:

Total =
SUMX (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[requested] = "TRUE" ),
        'Table'[id],
        'Table'[price]
    ),
    'Table'[price]
)

 

Be aware that if you have different values for the price in each ID you get the value twice depending on the option you need you may need to adjust this to the following:

Total =
SUMX (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[requested] = "TRUE" ),
        'Table'[id],
        "MAXIMUMPRICE", MAX ( 'Table'[price] )
    ),
    [MAXIMUMPRICE]
)

 

You can then adjust the MAX to minimum, average whatever value you need if the prices are different.

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

If for id 123, there was one TRUE and one FALSE, then would 150 be considered?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yueyunzh-msft
Community Support
Community Support

Hi , @auron 

According to your description, you want to ”SUM function with multiple condition“.

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can click "New Measure" to create a measure:

Measure = 
var _t2= SUMMARIZE(FILTER('Table','Table'[requested]=TRUE()), [id] ,"price" , MAX([price]))
return
SUMX(_t2 ,[price])

Then we can meet your need:

vyueyunzhmsft_0-1675908033634.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

MFelix
Super User
Super User

Hi @auron ,

 

Try the following code:

Total =
SUMX (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[requested] = "TRUE" ),
        'Table'[id],
        'Table'[price]
    ),
    'Table'[price]
)

 

Be aware that if you have different values for the price in each ID you get the value twice depending on the option you need you may need to adjust this to the following:

Total =
SUMX (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[requested] = "TRUE" ),
        'Table'[id],
        "MAXIMUMPRICE", MAX ( 'Table'[price] )
    ),
    [MAXIMUMPRICE]
)

 

You can then adjust the MAX to minimum, average whatever value you need if the prices are different.

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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