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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Set global variables a...
Power Apps
Answered

Set global variables and use it for progress bar (width)

(1) ShareShare
ReportReport
Posted on by 103

Hi,

Im trying to create a progress bar with just a rectangle using some metrics for the width entity.

 

1. Get the total number of rows in the sharepoint list so we know the total value and can use that to calculate 100%. I guess a good idea is to set this as a global variable so it can be used on all screens?

ClearCollect('SharePointList', Status);
Set(varCount, CountRows('SharePointList'));

 

I would also like to get the count of "Not started", "In progress" and "Completed" from that Status column so it can be used within other parts of the app and for this progress bar.

 

2. On the rectangle I need to divide the "Completed" count with the total row count to get the percentage right?

 

How can i set global variables of this all use those variables to get the width?

Categories:
I have the same question (0)
  • mmollet Profile Picture
    3,187 on at

    Screenshot 2023-05-31 at 3.39.58 PM.png

     

    Screenshot 2023-05-31 at 3.39.51 PM.png

     

    Like these? If so I have 2 labels stacked on top of eachother.

    Top Label holds the text you want to see and has a static width which will represent 100%

    Bottom label has this for its width: IfError(476 * ThisItem.LotsComplete/ThisItem.Lots,0)

    476 is my width of the top label, then you want to multiply that width by the % that you calculate in order to scale it to the correct size. The IfError function just takes care of any divide by 0 errors that may pop up. For my situation LotsComplete/Lots gives me the value I need however for yours you will have to decide what to use there.

     

    EDIT: using variables to do this is just a waste of resources and brain power in my opinion. That will just make more things to manage and more work for the app for absolutely no reason. You can use a single line of code and 2 controls or use a collection, 5 global variables and still the same controls plus a ton of logic. Chat GPT can give good answers but with Power Apps it generally doesnt give very optimal answers and in many cases doesnt give a valid answer at all. 

  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @fiddlerx 

    It seems like you are trying to build a progress bar in Power Apps based on a SharePoint list,
    where you want to show the percentage of "Completed" tasks compared to the total number of tasks.

     

    Here is some way you can try, to set global variables and use them to calculate the width of your progress bar:

     

    Set global variables
    You seem to be on the right track in terms of using global variables.
    You can use the Set function in Power Apps to set global variables.
    To get the count of each status, you can use the Filter function to filter your list based on status and then use CountRows to get the count. Here's how you might do it:

     

    ClearCollect(SharePointList, [Your SharePoint Data Source]);
    Set(varTotalCount, CountRows(SharePointList));
    Set(varNotStartedCount, CountRows(Filter(SharePointList, Status = "Not started")));
    Set(varInProgressCount, CountRows(Filter(SharePointList, Status = "In progress")));
    Set(varCompletedCount, CountRows(Filter(SharePointList, Status = "Completed")));

     

    Please replace [Your SharePoint Data Source] with your actual SharePoint data source name.

     

    Or preferably, just do it on the data source directly, let's suppose it's called SharePointList

     

    Set(varNotStartedCount, CountRows(Filter(SharePointList, Status = "Not started")));
    Set(varInProgressCount, CountRows(Filter(SharePointList, Status = "In progress")));
    Set(varCompletedCount, CountRows(Filter(SharePointList, Status = "Completed")));

     

     

    Use these variables to get the width
    To calculate the width of the rectangle, you need to find the proportion of "Completed" tasks compared to the total number of tasks. You can then multiply this ratio by the maximum width of your rectangle. Assuming maxWidth is the maximum width of the rectangle:

     

    Set(rectangleWidth, (varCompletedCount/varTotalCount)*maxWidth);


    Display the progress bar
    In your rectangle's width property, simply set it as rectangleWidth.

     

    Make a note that this solution assumes that the Status field in your SharePoint list is a text field.
    If it's actually a Choice field, you may need to adjust your code slightly to accommodate that.

     

    See if it helps @fiddlerx 

  • asusx540u Profile Picture
    36 on at

    Would you be so kind as to show me how I can modify the formulae for Choice fields? I'm encountering the same issue, it's just that, this time, I need to show "Not Started", "Pending", "On Hold", and "Completed". All these are choice columns, but I have the same logic above. Thank you.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard