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
Anonymous
Not applicable

count the occurrences by category

Hi,

 

I have following requirements:

see table below:

if Doc is blank then count-output = 0

but if there is Doc then count the occurrences of BIN based on NO., Type and BiN.

 

 

No.TypeBinDoccount -output
01AAABB12123
01AAABB32423
01AAABB5433
02ACCDD23121
03ABBDD43432
03ABBDD34322
04BAABB565231
02ACCDD 0

 

 

Appreacite your help!

Column/Measure is what i am looking for.

 

@Ashish_Mathur 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Picture1.png

 

Count-output CC =
SWITCH (
TRUE (),
'Table'[Doc] = BLANK (), 0,
COUNTROWS (
FILTER (
'Table',
'Table'[Doc] <> BLANK ()
&& 'Table'[No.] = EARLIER ( 'Table'[No.] )
&& 'Table'[Type] = EARLIER ( 'Table'[Type] )
&& 'Table'[Bin] = EARLIER ( 'Table'[Bin] )
)
)
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This calculculated column formula works

=

if(Data[Doc]=BLANK(),0,CALCULATE(COUNTROWS(Data),FILTER(Data,Data[No.]=EARLIER(Data[No.])&&Data[Doc]<>BLANK())))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This calculculated column formula works

=

if(Data[Doc]=BLANK(),0,CALCULATE(COUNTROWS(Data),FILTER(Data,Data[No.]=EARLIER(Data[No.])&&Data[Doc]<>BLANK())))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur  and @Jihwan_Kim ,

both the solutions works , but if I have a date filter , it is not filtering to show the count corectly.

Please see below table:

Now if I select date 6/21/2021 and No. 01 , it should bring count 2 and not 3 as on that date there were only 2 counts. 

also if I select No. 2 and date is 6/22/2021 then it will show 1 as there is only 1 record

it that something doable?

 

No.TypeBinDoccount dateoutput
01AAABB12126/21/20213
01AAABB32426/21/20213
01AAABB5436/22/20213
02ACCDD23126/22/20211
03ABBDD43436/21/20212
03ABBDD34326/22/20212
01BCCAA565236/21/20211
02ACCDD 6/21/20210

You wanted a calculated column formula solution.  Calculated column formlas do not update when slicer changes are made.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Jihwan_Kim
Super User
Super User

Picture1.png

 

Count-output CC =
SWITCH (
TRUE (),
'Table'[Doc] = BLANK (), 0,
COUNTROWS (
FILTER (
'Table',
'Table'[Doc] <> BLANK ()
&& 'Table'[No.] = EARLIER ( 'Table'[No.] )
&& 'Table'[Type] = EARLIER ( 'Table'[Type] )
&& 'Table'[Bin] = EARLIER ( 'Table'[Bin] )
)
)
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

if(isblank([Doc]) , blank(), countx(filter(Table, [Bin] =earlier([Bin]) && not(isblank([Doc]) )), [No.]))

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.