cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tejaswidmello
Impactful Individual
Impactful Individual

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/

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

@tejaswidmello , Try a new column like

 

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



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors