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
dgdgdg122db
Helper II
Helper II

Count occurrence with condition

Hi 

I have a table looks like this:

Capture2.PNG

What I want to achieve is to count the occurrence of the client no. where the Position is 10.

 

I want to use Card visualization in my report: 

1. have a total buying customer (the distinct count of client no) 20

2. 16 of them are buying for the first time ( the distinct count of client no =1 )

3. 4 of them are returning (the distinct count of client no >1)

 

The report should have three Cards:

22222.JPG

Please help 😞

 

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @dgdgdg122db 

We need just a few measures to get what you are looking for.

A count of all the rows, this we will use for filtering later.

Line Count = COUNTROWS ( 'Table' )

A count of the distinct customers (the 20)

Buying Customers = DISTINCTCOUNT ( 'Table'[Client no] )

The first time buyers

First Time Buyers = 
CALCULATE ( 
    [Buying Customers], FILTER ( VALUES ( 'Table'[Client no] ) , [Line Count] = 1 )
)

And the returning customers

Returning Customers = 
CALCULATE ( 
    [Buying Customers], FILTER ( VALUES ( 'Table'[Client no] ) , [Line Count] > 1 )
)

I'm not sure what you mean about the filter on position 10 but the position filed can be added as a page level filter and that will limit all the measures above to only calculate against the lines in position 10 if that is what you are looking for.

I have attached my sample file for you to look at.

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

Hello @dgdgdg122db 

We need just a few measures to get what you are looking for.

A count of all the rows, this we will use for filtering later.

Line Count = COUNTROWS ( 'Table' )

A count of the distinct customers (the 20)

Buying Customers = DISTINCTCOUNT ( 'Table'[Client no] )

The first time buyers

First Time Buyers = 
CALCULATE ( 
    [Buying Customers], FILTER ( VALUES ( 'Table'[Client no] ) , [Line Count] = 1 )
)

And the returning customers

Returning Customers = 
CALCULATE ( 
    [Buying Customers], FILTER ( VALUES ( 'Table'[Client no] ) , [Line Count] > 1 )
)

I'm not sure what you mean about the filter on position 10 but the position filed can be added as a page level filter and that will limit all the measures above to only calculate against the lines in position 10 if that is what you are looking for.

I have attached my sample file for you to look at.

Hi @jdbuchanan71  

Thank you very much for your help! 

 

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.

Top Solution Authors