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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
lynnpowerbi
Frequent Visitor

SUM with Multiple Filters with Ordering

Hi, 

 

I've been struggling to come up with a piece of DAX code that will filter in order. 

 

I currently have a data table that has duplicate Case IDs with each Case ID having different process outcome date times. What I'm trying to calculate is the Total Errors per Case ID. This would mean it will need to follow the order of 1. filtering on a group of case IDs that share the same ID and then 2. filtering on the MIN process outcome date row and finally 3. Totalling the number of errors associated with the case ID.

 

I tried to create a calculated column below but it didn't work. Should I create a calculated table or a measure instead? 

 

 

 

 

 

 

Total Errors per Case ID = 

var caseidvar = Table[caseid]
return

var minprocessouttcomeddate = CALCULATE(MIN(Table[processoutcomedatetime]), FILTER(Table[caseid]))
return 

    CALCULATE(
    SUM(Table[Category 1 Errors])
    + SUM(Table[[Category 2 Errors])
    + SUM(.......)
   ),
    FILTER(Table, Table[caseid] = caseidvar && Table[processoutcomedatetime] =  minprocessouttcomeddate)
    )

 

 

 

 

 

 I tried another piece of DAX code that led to double counting the errors (e.g if Case ID 123 has three rows with three different process outcome dates and 2 errors showing up, it returned as 6 when it should be 2).

 

The reason why I am using MIN for process date time is because sometimes the same case can have different number of errors recorded depending on the time stamp.  

 

Your help would be very much appreciated!! Thank you in advance

2 REPLIES 2
Anonymous
Not applicable

Hi @lynnpowerbi ,

 

According to your statement, I think you want to count the error for each Case ID. I think the table currently should look like ([Case ID]/[Category 1 Errors]/[Category 2 Errors]...).

I suggest you to try UNPIVOT function to transform your table. Select all column with format [Category N Errors] and unpivot them.

For reference:

Unpivot columns

Then you just need to distinctcount for each ID to get result.

 

Best Regards,
Rico Zhou

 

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

 

Hi Rico, 

 

Thanks for your reply. My raw dataset is currently set up this way - 

Case IDProcess outcome date timeError 1.1Error 1.2Error 2.1Error 2.2
1001/1/2023 11 
1002/1/2023 1  
1013/1/20231  1
1014/1/20231   

 

I have at least 20+ error code columns in raw data. Should I unpivot the error code columns first or should I start grouping the error categories first? 

 

My end goal is

1. to be able to calculate total errors for Case 100 to be 2 and Case 101 to be 2 (following the criteria that we only want Min Process Outcome Date Time) 

2. Similiarly, to be able to calculate the # error categories for Case 100 and 101 to be 2.  

 

Thank you

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors