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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kirwanm1
Frequent Visitor

CountIF based on grouping ID

Hey Everyone, 

So I have the following table structure as a series of events with each line representing a row.


Grouping ID - Event

Event A - Trigger 1
Event A - Trigger 2
Event A - Trigger 3
Event B - Trigger 1
Event B - Trigger 3
Event C - Trigger 1
Event C - Trigger 3
Event D - Trigger 1
Event D - Trigger 2
Event D - Trigger 3
Event E - Trigger 1
Event E - Trigger 2
Event E - Trigger 3

 

I'm struggling to find a function that will allow to count the number of events that contain two triggers.
I.e. countingfunction(Trigger 2, Trigger 3) returns 3.
Because Trigger 2 & Trigger 3 are in events that share the same aggregate id. Event A, Event D & Event E

countingfunction(Trigger1. Trigger 3) returns 5 as Trigger 1 and Trigger 3 are in all three events.

Does anyone have some advice on how to go about this in Power BI?

Thanks!

9 REPLIES 9
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @kirwanm1,

Please try to resolve your issue based on @vanessafvg and @MarcelBeug posted. If you have any other problem, plesae feel free to ask.

Kind Regards,
Angelia

vanessafvg
Super User
Super User

@kirwanm1

 

are you saying you want to calculate the rows where these 2 events are present?

 

 

measure = calculate(countrows(table), Event = "Trigger 1" || Event = "Trigger 2")





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




No Sorry, for the confusion, they are two seperate columns in the above example.

 

I want to group all the event ids together, and calculate how many events where the event rows contain two inputs.

@kirwanm1  well if you using a visual  where you place the event  on it and then have a measure like

 

measure = distinctcount(column)  on the trigger column that should give you a distinct count of triggers per event, when you place those 2 fields you will get the event with the unique count of triggers

 

unless you want to do a count of all events, are the triggers duplicated per event?  and if so are you wanting to know that?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




No thats not it. I need to group based on the first column. 

ID          Event

1            Yes

1            No

1            Maybe

2            Yes

2            Yes

2            No

3            Maybe

3            Yes

3            No

So that is the table above. I need a distinctcount of the ID above which would be three 3. Filtered to only include if the Event contains a No & Maybe, which would be 2 as id no.2 contains no maybes. Does this make sense?

No/Maybe =
COUNTROWS (
INTERSECT (
CALCULATETABLE (
DISTINCT ( Table[id] ),
'Table'[Event] = "No"
),
CALCULATETABLE (
DISTINCT (Table[id] ),
Table'[Event] = "Maybe"
)
)
)

 you can also give this a go @kirwanm1





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@kirwanm1

 

it does make sense yes, it sounds like you would get the result for each i.e maybe and then no and then merge where there is only both,i will have to think deeper on how to do it





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




This would be my suggestion for the countingfunction:

 

(Trigger1 as text, Trigger2 as text) as number =>
let
    Selection1 = Table.SelectRows(Table1, each [Event] = Trigger1),
    Groups1 = Selection1[#"Grouping ID"],
    Selection2 = Table.SelectRows(Table1, each [Event] = Trigger2),
    Groups2 = Selection2[#"Grouping ID"],
    Count = List.Count(List.Intersect({Groups1,Groups2}))
in
    Count
Specializing in Power Query Formula Language (M)

makes sense to do it in powerquery @MarcelBeug





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.