Support » Plugin: Calculated fields for ACF » Count fields with same values

  • Resolved Demode

    (@webdemodehr)


    Is it possible to count only fields with same value inside repeater filed?

    Thanks a lot – great plugin!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author wundermatics

    (@wundermatics)

    Hi,

    That’s not possible today. The underlying math library in use doesn’t have a good way to express conditional values which is a limiting factor right now. But we’d be happy to extend it if it makes good sense.

    We’re interested to understand what your use case is so that we know that we aim for the right functionality. We have thought about implementing something similar to the Excel formula COUNTIF, is that what you are looking for?

    Looking forward to hear more from you.

    Plugin Author wundermatics

    (@wundermatics)

    As of version 1.2.0, conditional operators are supported in the plugin. This means that you can type formulas like “amount > 20”.

    This also means that you can do a simple version of “COUNTIF”. Assuming you have a repeater field named “products” containing fields “price” and “quantity”. Using a conditional operator like “==” or “>=”, you can now create a calculated field like this:

    sum(products.quantity >= 5)

    The quantity > 5 part will return 1 for any row that has a value of 5 or greater and zero for all other rows. The sum function will summarize this so that the returned value will be a count of the number of rows where quantity > 5

    Please let us know if this was what you were looking for.

    Demode

    (@webdemodehr)

    Hi,

    first of all, thanks a lot, you are very helpful – and really sorry to bother you with my dilemmas / challenges 🙂

    Let me try to explain what exactly our task is, so maybe you have even better and simpler solution.

    We are trying to build the score board – repeater field with following sub fields:
    – Rank
    – Category
    – Contestant

    So every time when rank value is 1 – it means “gold medal”, if value is 2 it’s “silver”, and value 3 “bronze”. As every competition has multiple competitors and ranks (scores), and the idea is to list, at the end of the scoreboard, exact count of gold, silver and bronze medals.

    Example:

    “Total competitors 145 // Total medal 12 (6 gold, 4 silver and 2 bronze)”

    Challenge is that we trying to build entire web page trough Elementor with ACF based input, and even is great page builder and ACF is great form builder, it has some limitations. We would really try to avoid and alterations in “functions.php” file and and any short code placing inside Elementor. Hope that we can do everything with just plugins and basic tools.

    “COUNTIF” sounds very interesting – maybe I will make it work with that new function – I will certainly try right away.

    Once again, thanks a lot for your time, and if you have any better idea – I would be grateful.

    Demode

    (@webdemodehr)

    Hi again,

    I’ve tried it – and here are my results

    sum(products.quantity >= 5) – works great! – even variation sum(products.quantity > 5) – seams to be working just fine

    but

    sum(products.quantity == 5) or sum(products.quantity = 5) – I can make it work 🙁

    As I see it now function == would be solution to all my problems – I think that’s exactly what I need – count the columns with desired number. Any thoughts what am I doing wrong and why doesn’t it work for me?

    Thanks.

    Plugin Author wundermatics

    (@wundermatics)

    Hi again,

    Many thanks for your detailed feedback, both on your use case and the results you had with version 1.2.1.

    As you might suspect, a bug sneaked in and the == was internally interpreted as a (malformed) assignment operator. We’ve fixed that now, added it into our unit tests and released version 1.2.2. Any feedback from you will be appreciated.

    Leaving this issue open until we hear back.

    Plugin Author wundermatics

    (@wundermatics)

    Hi, didn’t hear back from you in a couple of days. The issue was solved in release 1.2.2 and to the best of our knowledge the fix solves your problem. Let us know otherwise.

    Demode

    (@webdemodehr)

    Sorry for not replying sooner, but this time “real life bug” sneaked up to me so I was in bed for a couple of days. However, I did try the update and – EVERYTHING works fine now, just as it should 🙂 Thank you, thank you! Once again – great plugin and great support!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.