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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
swisdom
Helper I
Helper I

Running count of occurrences, with filters

I have a long set of data consisting of unit serial numbers, service dates, and Service Numbers.

I want to create a running count of the number of times each Serial Number has been returned, ordered by occurance.

To complicate things further, there are multiple "types" in the data - a serial number may appear in more than one type, but I only want to count if Type = "Serv" (if it helps, in instances where the Type is anything other than Serv, there will be no SVO number). Also, frequently multiple lines will be created for the same return, indicated by an alpha character at the end of the SVO number. In these cases, I do not want it to count as a separate occurance.

I tried creating an Index column to help, but I'm not sure if it is actually useful.

 

An example of my data, and what I would like to create in the last (red) column:

 

Type Serial SVO Date Occurance
Serv 

123456 

83812 6/9/2022 1
Test 123456  3/30/2022 NA
Serv 456789 74659 2/4/2020 1
Serv 789129 76598 6/12/2021 1
Serv 

123456 

84749 10/30/2022 2
Serv 567890 84505 1/19/2022 1
Serv 567890 84505A 1/20/2022 NA
Serv 123456 84596 1/3/2023 3
Serv 567890 86954 1/30/2022 2

 

What I've got so far is just a flat count, which seems to work OK except it doesnt do the exclusions, and it doesnt number them by occurance

 

Multi Count = 
    COUNTX (
    FILTER ( 'Data', EARLIER ( 'Data'[SERIAL] ) = 'Data'[SERIAL]), 'Data'[SERIAL] )

 

This gives something like this:

Type Serial SVO Date Occurance
Serv 

123456 

83812 6/9/2022 4
Test 123456  3/30/2022 4
Serv 456789 74659 2/4/2020 1
Serv 789129 76598 6/12/2021 1
Serv 

123456 

84749 10/30/2022 4
Serv 567890 84505 1/19/2022 3
Serv 567890 84505A 1/20/2022 3
Serv 123456 84596 1/3/2023 4
Serv 567890 86954 1/30/2022 3

 

I've also tried this, but it seems to just give.. I'm not sure, some sort of nonsense that isn't what I'm looking for:

 

Multi Occurance = 
calculate( countrows('Data'), 
filter('Data', 'Data'[TYPE] = "Serv" &&
'Data'[SERIAL] = earlier('Data'[SERIAL]) &&
not( left('Data'[SVO],5) = left(earlier('Data'[SVO]),5) )))

 

I appreciate any help!

1 ACCEPTED SOLUTION
bolfri
Super User
Super User

NA_logic = 
SWITCH(TRUE(),
    'Sample'[Type]<>"Serv","NA",
    NOT(RIGHT([SVO],1) in {"0","1","2","3","4","5","6","7","8","9"}), "NA",
    "OK"
    )

It's better to split this into two columns. 🙂

Multi Count = 
var serial = 'Sample'[Serial]
var current_date = 'Sample'[Date]
var multicount =
    COUNTROWS(
        FILTER('Sample',
        'Sample'[NA_logic] <> "NA"
        && 'Sample'[Serial]=serial
        && 'Sample'[Date] <= current_date
        )
    )
return IF('Sample'[NA_logic] <> "NA",multicount,0)

 Result:

bolfri_0-1677793985542.png

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
bolfri
Super User
Super User

NA_logic = 
SWITCH(TRUE(),
    'Sample'[Type]<>"Serv","NA",
    NOT(RIGHT([SVO],1) in {"0","1","2","3","4","5","6","7","8","9"}), "NA",
    "OK"
    )

It's better to split this into two columns. 🙂

Multi Count = 
var serial = 'Sample'[Serial]
var current_date = 'Sample'[Date]
var multicount =
    COUNTROWS(
        FILTER('Sample',
        'Sample'[NA_logic] <> "NA"
        && 'Sample'[Serial]=serial
        && 'Sample'[Date] <= current_date
        )
    )
return IF('Sample'[NA_logic] <> "NA",multicount,0)

 Result:

bolfri_0-1677793985542.png

 





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

Proud to be a Super User!




That worked perfectly, thank you!

bsheffer
Continued Contributor
Continued Contributor

sounds like you could do this with a simple calculate(countrows('data'), with a filter clause to remove anything you don't want.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.