Skip to main content

How can I count shapes of the same color? I have multiple circles of different colors and I want to count number of circles with the same color.

How can I count shapes of the same color? I have multiple circles of different colors and I want to count number of circles with the same color.

@Grady would love to help you yet tried my best on my side and couldn't find a way (


Good morning,

I have good news! I checked with our formula wizards, and I got the formula that you will use. To start you will need to be using Lucidchart. If your current diagram is in Lucidspark, simply use our fast product switching by clicking in the upper left corner of your document on the Lucidspark icon, and then select “edit in Lucidchart”. 
 



Next you will need to know the hex code of the colors you want to count. I did this by selecting the shape on the canvas that I needed to know the hex code for > selecting the color picker (the paint bucket icon) > selecting the plus sign in the bottom of the popup > and you can see the hex code to the right (see screenshot for reference). 


Next step is to add a formula to the page in the contextual panel. You can access this by clicking anywhere blank on the canvas > In the right hand upper corner you will select the little square (contextual panel) > then select the button to add a new data field. 
 

 

Next you will add the formula below (copy/paste it from the text below) in the “Property 1” field. You will need to edit the formula to use the hex code you identified following the previous steps. You can simply hit enter after you have entered the hex code.

* (One thing I noticed was that as I typed the new hex code, it kept the previous hex code there, so I just deleted that and made sure the one I wanted was the only one entered, it should only ever be 6 characters in length).

 

=COUNTIF(children(page), x => FILLCOLOR(x)

= HEXCOLOR('#e3fae3'))


 

 

You will see the number change in the field below the “Property 1” field which indicates how many shapes are using that hex code (color) to fill. If you want you can change the name of the “Property 1” field to anything you prefer to call it. 
 

 

Let me know if you have any questions! I hope this helps! 


Oh, and I forgot to mention that you can add additional properties for each new color by adding the formula in the “Property 2” field, and another in “Property 3” field, etc. Just change the hex code each time for the coordinating color.


Thank you for the reply, I followed your instructions and its kind of working. It seems to be counting all shapes regardless of color. 

=COUNTIF(children(page), x => FILLCOLOR(x)  = HEXCOLOR('7AB648'))

is what I put in properties 1. Plus its adding 1to the count, if I select just one shape it says there is two. Its counting something but does not seem to be counting shapes of the color I put the hex code for.

Any additional information would be much appreciated.


Hi Grady! It looks like you need the “#” sign in front of your hex code. Try that and tell me if it changes. 


This is what Im working with. I want to count the green, purple and blue circles individually. 


@Shantel Gillette great guide! 


Good morning Grady,

Did adding the “#” sign in your formula work? The area where you put in the 6 digit hex code needs the # in front of it. Then you would add three properties (one for each color you want to count), and change the hex code for each color. 


# didnt help, its just giving me the total number of shapes. =COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR(' #7AB648'))


Good morning! 

I copied/pasted your formula, and I noticed a space right here (see screenshot). Once I deleted that, the formula worked as expected.

 


Hey all, I can never get more than “0” for the count, even though I have tried multiple hex colors of different objects, I always get zero. How do I know it is looking at all the objects, and not just the background, as it’s selection search set, etc?


Hello @ConRob,

If you could share your formula that would be useful to help identify why it is only returning 0. 

 

I also wanted to show you how to edit an existing property that you asked about. If you click on the property, the popup should show you the formula you’ve entered. You just click into the formula to edit.
 

 


Thank you for your help!! Okay, here is what I am running into. I either get 0 or I get 17 (no matter the hex value) but I can never get an accurate count.

I get “0” with this syntax… (no space)
=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR('#6db1ff'))

=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR('#ff80df'))

=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR('#ced4db'))

I get “17” with this syntax… (space after aopostrophe)
=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR(' #6db1ff'))

=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR(' #ff80df'))

=COUNTIF(children(page), x => FILLCOLOR(x)= HEXCOLOR(' #ced4db'))

 

Tried other syntax, like removing the apostrophes all together, but that also gives “0”


@ConRob Jumping in to support, too! I’d love to take a closer look at your document. Would you please share a document support PIN for this document? This is for internal use only and won’t grant public access to your document, so you can share it safely here in this thread. You can follow the instructions in this Generate a Lucid Support PIN article from our help center to do so!


I cloned the doc and deidentified it anyway
temp support pin is bJ4K9MTDJk29


Hi ​@ConRob, thanks for your response. I just attempted to take a look at your document, but I didn’t realize that your account has Strict Privacy enabled, which means I’m not able to view your document in this way. If you’re willing to share your cloned, deidentified document with me directly, I’ll be able to continue assisting you. I’ll privately message you the email address you can share the document with! My apologies for the miscommunication.


Thank you, I have added you to the doc


Thank you for your help and patience ​@ConRob! We’ll take a closer look and reach out shortly.


Good morning ​@ConRob,

I checked with a colleague that is much better with formulas than myself, and I asked them if the org chart shapes you are using could be causing the issue.  Here is their response, and I hope this assists in solving this for you.

Formulas do work with org charts, generally, and can work with page-level formulas. The second example is giving 17 likely because HEXCOLOR(' #......') return white, due to it not being a valid color with the extra space). I believe what the user will likely want is DESCENDANTS not just CHILDREN (since CHILDREN is one-level down, it's just getting the org chart itself, not any of the people in the org chart).Here's an example:
 

One note is that the formula will count everything with that color (in my example, it includes the sticky note with the same fill color, which is why it's getting 3). To get only the org chart shapes, changing the formula to look at DESCENDANTS of the org chart shape (instead of the page) or filtering by type (e.g. something like =COUNTIF(DESCENDANTS(page), x => AND(SHAPETYPE(x) = 'TreeNodeBlock', FILLCOLOR(x) = HEXCOLOR("#e3fae3")))) should work.


That worked, thank you so much! Now I need to figure out how to do combinatorial queries based on role text and hex color. For example, if I want to get a separate count of FTEs vs Consultants within the Engineers that are all blue.

Is there any good training or documentation you can point me do for up-skilling my Lucid formula logic/syntax that I could dive into?


Hi ​@ConRob

Jumping in to suggest the Help Center article, Use formulas in Lucidchart, as a great starting point. Additionally, you can read through the developer documentation on formulas and syntax. Please let us know if there is anything else we can do to support your work!


Hi there,

Thank you for posting and sharing! ​@Shantel Gillette I am using this formula with success but its returning 1 extra. I thought it might be picking up two from the Swimlane lane and header, but when I tested it, that didn’t seem to be the issue. Where can I add -1 into the formula? Or is there an edit I should make make to the formula?
 

 


Hi ​@ErmGord, thanks for adding to this thread! I’m currently working in a support ticket with your colleague on your document. It appears that it may be counting an extra due to a potential bug with Swim lane hex codes. ​@Shantel Gillette, if you have any insights though, based on the formula, please let me know!


Reply