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
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
v-stephen-msft
Community Support
Community Support

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

v-stephen-msft
Community Support
Community Support

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
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

Top Solution Authors