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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
mheyde
New Member

Counting/Summing values based on a fields information

Hi,

 

I am trying to COUNT and SUM values of a table based on particular conditions/values of other cells.

 

Example: 
SUM "Amount" where "OrderType"= Refund

Expected Result: -30,00

 

or

COUNT "ItemQuantity" where "OrderType"= Order and "OrderDate" 25.10.2022<26.10.2022

Expected Result: 6

 

Sample Data:

mheyde_1-1670425040506.png

 

Thank you for your help

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @mheyde ,

 

Based on your sample data and expected results, you can create two measures.

Measure = CALCULATE(SUM('Table'[Amount]),FILTER('Table',[OrderType]="Refund"))
Measure 2 = CALCULATE(SUM('Table'[ItemQuantity]),FILTER('Table',[OrderType]="Order"&&[OrderDate]>=DATE(2022,10,25)&&[OrderDate]<=DATE(2022,10,26)))

vstephenmsft_0-1670469003334.png

However, the above two formulas will dynamically change the result according to the filtering of slicers or filters, such as the following cases.

vstephenmsft_1-1670469076033.png

If you want to remove the slicer's filter, add the ALL function to it.

Measure = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[OrderType]="Refund"))
Measure 2 = CALCULATE(SUM('Table'[ItemQuantity]),FILTER(ALL('Table'),[OrderType]="Order"&&[OrderDate]>=DATE(2022,10,25)&&[OrderDate]<=DATE(2022,10,26)))

vstephenmsft_2-1670469143630.png

 

 

Best Regards,

Stephen Tao

 

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

View solution in original post

2 REPLIES 2
mheyde
New Member

It works. thank you so much

Anonymous
Not applicable

Hi @mheyde ,

 

Based on your sample data and expected results, you can create two measures.

Measure = CALCULATE(SUM('Table'[Amount]),FILTER('Table',[OrderType]="Refund"))
Measure 2 = CALCULATE(SUM('Table'[ItemQuantity]),FILTER('Table',[OrderType]="Order"&&[OrderDate]>=DATE(2022,10,25)&&[OrderDate]<=DATE(2022,10,26)))

vstephenmsft_0-1670469003334.png

However, the above two formulas will dynamically change the result according to the filtering of slicers or filters, such as the following cases.

vstephenmsft_1-1670469076033.png

If you want to remove the slicer's filter, add the ALL function to it.

Measure = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),[OrderType]="Refund"))
Measure 2 = CALCULATE(SUM('Table'[ItemQuantity]),FILTER(ALL('Table'),[OrderType]="Order"&&[OrderDate]>=DATE(2022,10,25)&&[OrderDate]<=DATE(2022,10,26)))

vstephenmsft_2-1670469143630.png

 

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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