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

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Invalid Operation Division by Zero

(0) ShareShare
ReportReport
Posted on by 78
Hello community,
 
Build a pagination for Table grid, getting an error "Invalid Operation Division by Zero" on Pagination text label.  Value of varPage and varRowsPage is 
UpdateContext({varPage: 1, varRowsPerPage: 10});
 
 
Anyone know how to resolve this issue?
I have the same question (0)
  • ronaldwalcott Profile Picture
    3,827 Super User 2025 Season 2 on at
    Invalid Operation Division by Zero
    Please provide more details. What is your data source, SharePoint or Dataverse? Is that a gallery or a table?
  • SR-02111122-0 Profile Picture
    78 on at
    Invalid Operation Division by Zero
    DataSource = SharePoint list, It's a gallery
  • WarrenBelz Profile Picture
    151,934 Most Valuable Professional on at
    Invalid Operation Division by Zero
    The gallery is resolving when the screen opens before the variable is set. Try putting the variable in the navigation to the page.
    Navigate(
       YourScreenName,
       ScreenTransition.None,
       {varPage: 1, varRowsPerPage: 10}
    )
    The other option is a Global (Set) variable you can do before you enter the screen.
    Set(
       gblPage,
       1
    );
    Set(
       gblRowsPerPage, 
       10
    }

    then use those two values.  I named them differently as any further setting of the same name (varPage etc) using UpdateContext is a completely different variable which will take precedent over the one you used Set to create/update.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee

  • Suggested answer
    Garima_PowerPlatform Profile Picture
    170 on at
    Invalid Operation Division by Zero
     
    set global variables in the app's OnStart property or prior to navigation:
    Set(varPage, 1)
    Set(varRowsPerPage, 10)
    Navigate(YourScreenName)

    This method initializes variables globally for the entire session.

    Conditional Setting of Variables:

    Ensure that if the table or gallery is dependent on these variables, they are checked and updated before the pagination is processed:

     
    If(
      IsBlank(varPage) || varPage = 0,
      Set(varPage, 1),
      UpdateContext({varPage: varPage, varRowsPerPage: varRowsPerPage})
    )
     
  • SR-02111122-0 Profile Picture
    78 on at
    Invalid Operation Division by Zero
    Hi @WarrenBelz
     
    Set the variables OnStart property of App still getting same Error Invalid Operation Division by Zero
     
     
    Set(varPage, 1);
    Set(varRowsPerPage, 10);
    Set(varPageRepair, 1);
    Set(varRowsPerPageRepair, 10);
  • WarrenBelz Profile Picture
    151,934 Most Valuable Professional on at
    Invalid Operation Division by Zero
    Did you get rid of all other references to the Variables using UpdateContext ? If you did not, then the context variable, which will not be set will take precedent, which is why I suggested you use different names for the Variables.
  • SR-02111122-0 Profile Picture
    78 on at
    Invalid Operation Division by Zero
    Yes, removed the Update Context variables
  • WarrenBelz Profile Picture
    151,934 Most Valuable Professional on at
    Invalid Operation Division by Zero
    Can you please try another variable name as this is not making a lot of sense based on what you have posted. The only thing you are dividing by is varRowsPerPage and providing you set that to a number bigger than zero before you enter the screen, there is no reason you should get that error. Are you sure also that there is no other formula on the page involving a division formula.
  • SR-02111122-0 Profile Picture
    78 on at
    Invalid Operation Division by Zero
     
    I have this formula on gallery Items Property
     
    With(
        {
            // Apply filters based on the selected criteria
            _Data: Filter(
                'Purchase Requisition',  // The data source (e.g., SharePoint list)
                (
                    (CheckboxApproved.Checked && Status.Value = "Approved") ||
                    (CheckboxPending_1.Checked && Status.Value = "Pending") ||
                    (CheckboxRejected_2.Checked && Status.Value = "Rejected") ||
                    (!CheckboxApproved.Checked && !CheckboxPending_1.Checked && !CheckboxRejected_2.Checked)
                ) &&
                (IsBlank(varStatusFilter) || Status.Value = varStatusFilter) &&
                (IsBlank(DatePickerCanvas1_1.SelectedDate) || 'Date of Requisition' >= DatePickerCanvas1_1.SelectedDate) &&
                (IsBlank(DatePickerCanvas2_2.SelectedDate) || 'Date of Requisition' <= DatePickerCanvas2_2.SelectedDate) &&
                (IsBlank(txtInput_MinPrice.Value) || Price >= Value(txtInput_MinPrice.Value)) &&
                (IsBlank(txtInput_MaxPrice.Value) || Price <= Value(txtInput_MaxPrice.Value)) &&
                (
                    Len(txtInput_Search_2.Value) = 0 ||
                    txtInput_Search_2.Value in Text(ID) ||  // Search by ID
                    txtInput_Search_2.Value in 'Date of Requisition' ||  // Search by Date of Requisition
                    txtInput_Search_2.Value in 'Requisitioned by'.DisplayName ||  // Search by Requisitioned by
                    txtInput_Search_2.Value in Location.Value ||  // Search by Location
                    txtInput_Search_2.Value in Department.Value ||  // Search by Department
                    txtInput_Search_2.Value in Status.Value ||  // Search by Status
                    txtInput_Search_2.Value in 'Approved by'.DisplayName  // Search by Approved by
                )
            )
        },
        // Get total number of filtered records after search
        With(
            {
                filteredDataCount: CountRows(_Data)
            },
            // Apply pagination: display the correct set of records for each page
            // Skip records based on the current page (varPage) and display the correct number of records (varRowsPerPage)
            FirstN(
                LastN(
                    _Data,
                    filteredDataCount - ((varPage - 1) * varRowsPerPage) // Skip records for previous pages
                ),
                varRowsPerPage // Limit the number of records per page (e.g., 10 per page)
            )
        )
    )
  • Shravyashree_Shetty Profile Picture
    49 on at
    Invalid Operation Division by Zero
    Hi, 
    Please Try the below code ! [I have tried and it fixed the issue]
     
     varPageNumber & " of " & RoundUp( CountRows(galHidden.AllItems) / (Gallery4.Height /Gallery4.TemplateHeight),0)
     
    Another weird thing is, when you remove and add the code in all places where "/" is used, it gets rid of the error (strange but works)

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

Coming soon: forum hierarchy changes

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

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 624 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 384 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 246

Last 30 days Overall leaderboard