web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Count values within a ...
Power Apps
Answered

Count values within a record - Model Driven App

(0) ShareShare
ReportReport
Posted on by 20

Hi Community,

I am hoping someone can assist with an issue that I am struggling with. 

I have a Model driven app that I have developed for Project Managers.  One of the tables within this app has 4 columns that I need to interrogate.  Each Column has a value of either RED, AMBER or GREEN.  What I need to do is count the number of RED values, the number of AMBER values and the number of GREEN values.

Whilst this would appear to be easy to do, I have not been able to get any any solution (using Business Rules, Calculated fields or Formula fields) to work.

 

Does anyone know how I can get the counts that I need.

 

thanks

 

@cc_cathy64 

 

  

Categories:
  • Rusk Profile Picture
    1,369 Super User 2024 Season 1 on at

    Hi @cc_cathy64 

     

    If these columns have a text value of RED, AMBER or GREEN, you can use CountIf: https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-table-counts

     

    CountIf(YourDataSource,Column1 = "GREEN")

     

    Here's an example:

    Rusk_0-1677018910399.png

     

    If you wanted to sum these up, maybe to get a % of how many are in each color, you can just add them together:

    CountIf(colTest,Column1 = "GREEN") + CountIf(colTest,Column2 = "GREEN") + CountIf(colTest,Column3 = "GREEN") + CountIf(colTest,Column4 = "GREEN")

    Rusk_0-1677019650541.png

     

    If these columns have conditional formatting and are simply highlighted colors, that's a different story.  Can you share more details about your data source?  You mentioned it's a table within Power Apps, but what is the data source of that table?

  • cc_cathy64 Profile Picture
    20 on at

    Hi @Rusk 

    Thanks for your examples.  I tried this out, but did not work. My screen does not show a function entry area...

    In terms of your questions, the data source is a dataverse table.  The columns that contain the values that I want to sum, are calculated fields (values copied from another related table). 

    I have tried to follow your instructions, but I can't get it to work.

    I created a new column in the table with a formula datatype (Formula is in Preview), and tried to enter the values as you advised.  

    CountIf(msdyn_projectstatusreport,'Calculated Finance' = "GREEN")
     
    I get errors that CountIf is unknown or unsupported
    And it does not recognise the tablename.
     
    I am not sure if it is a system issue that CountIf is not available or what.
     

     

     

  • Rusk Profile Picture
    1,369 Super User 2024 Season 1 on at

    Hi @cc_cathy64 

     

    I haven't worked with model driven apps (I always use Canvas).  I've read there is some rigidity in their design so this could be a result of that.  Hopefully someone more knowledgeable than I can confirm if that's the issue here.

  • Rusk Profile Picture
    1,369 Super User 2024 Season 1 on at

    @cc_cathy64 

     

    Another thought:  Perhaps you can use a dashboard or chart to get that info as well:  https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/create-edit-system-chart

     

    Not sure if that would work... just an idea  ^__^

  • cc_cathy64 Profile Picture
    20 on at

    Hi @Rusk ,

    Charts wont work as you can't use the totals that it calculates.

    I cant believe this is so hard.

    To give you some further context:

    I have a table of Project records.  Each project record has 4 columns (Finance calculated, Risk calculated, Issue calculated and Schedule calculated). Each of these columns contains either RED, AMBER or GREEN as text which I set via a Business rules (and this all works fine).

    Now I need to determine the number of RED, AMBER and GREEN for each project record, so that I can use these values to calculate an overall status.

    Maybe I can create a Canvas app that does the sums and I can embed this within the Model app.  If you can provide advice on what the formula within the Canvas app would need to be to achieve what I want it would be really helpful.

     

    @cc_cathy64 

     

  • Verified answer
    Rusk Profile Picture
    1,369 Super User 2024 Season 1 on at

    @cc_cathy64 

     

    Good morning!  Here's an example that I hope is what you were describing.  The first table is my data source, the 2nd is the "modified" table using AddColumns, where I've summed the values for each row:

    Rusk_0-1677083826791.pngRusk_1-1677083861391.png

    Formula example:

    AddColumns(Project,
    "SumGreen",If(Finance="GREEN",1,0) + If(Issue="GREEN",1,0) + If(Risk="GREEN",1,0) + If(Schedule="GREEN",1,0),
    "SumAmber",If(Finance="AMBER",1,0) + If(Issue="AMBER",1,0) + If(Risk="AMBER",1,0) + If(Schedule="AMBER",1,0),
    "SumRed",If(Finance="RED",1,0) + If(Issue="RED",1,0) + If(Risk="RED",1,0) + If(Schedule="RED",1,0))

     

    And you don't have to use AddColumns in another table, it could also be added to a Collection or something like that.  Here's an example:

    Rusk_2-1677084059573.png

    Rusk_3-1677084076971.png

     

    Not sure if this is what you had in mind but hopefully it helps  ^__^

     

  • cc_cathy64 Profile Picture
    20 on at

    Hi @Rusk 

    This has definitely moved me forward.  Thanks so much.

    I have managed to add the Sum columns into the table.  Now I am just trying to get the fields to show up in the table in the model app.

     

    thanks heaps for the formula.

     

    @cc_cathy64 

     

  • cc_cathy64 Profile Picture
    20 on at

    Hey @Rusk ,

    Within the Canvas app, the fields are showing in the Projects table.  However, when I view the table via the dataverse the fields do not show up.  Sorry if I am asking silly questions, but I am not very experienced with Canvas apps.  Is there another step needed to get the fields to save into the table??

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard