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 / Invalid Operation Divi...
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?
Categories:
I have the same question (0)
  • Suggested answer
    Garima_PowerPlatform Profile Picture
    170 on at
    Try this

    Ensure varPage and varRowsPerPage Have Valid Values:

    • The formula explicitly uses Max() to ensure varPage is at least 1.
    • Example: Max(1, varPage) ensures varPage will never be 0 or negative.

      Handles Uninitialized Variables:
    •  
    • If varRowsPerPage is not set properly, ensure it's initialized in the OnStart property of the app or during the setup:
    • Set(varRowsPerPage, 10);
      Set(varPage, 1);

      Revised Code
       
    With(
        {
            _Data: Filter(
                'Purchase Requisition',
                (
                    (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 ||
                    StartsWith(Text(ID), txtInput_Search_2.Value) ||
                    StartsWith('Date of Requisition', txtInput_Search_2.Value) ||
                    StartsWith('Requisitioned by'.DisplayName, txtInput_Search_2.Value) ||
                    StartsWith(Location.Value, txtInput_Search_2.Value) ||
                    StartsWith(Department.Value, txtInput_Search_2.Value) ||
                    StartsWith(Status.Value, txtInput_Search_2.Value) ||
                    StartsWith('Approved by'.DisplayName, txtInput_Search_2.Value)
                )
            )
        },
        With(
            {
                filteredDataCount: CountRows(_Data)
            },
            FirstN(
                LastN(
                    _Data,
                    Max(0, filteredDataCount - ((Max(1, varPage) - 1) * varRowsPerPage))
                ),
                varRowsPerPage
            )
        )
    )
    Please Mark me verified if it could help you out.
  • WarrenBelz Profile Picture
    153,599 Most Valuable Professional on at
    Not sure how to comment further here - the only division formula you have posted is using varRowsPerPage and providing that Variable contains a value (other than zero) before the page is loaded, there is no reason for that error. Did you try using different Variable names and using Set() to make them global variables ?
  • Shravyashree_Shetty Profile Picture
    49 on at
    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)
  • SR-02111122-0 Profile Picture
    78 on at
     
    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)
            )
        )
    )
  • WarrenBelz Profile Picture
    153,599 Most Valuable Professional on at
    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
    Yes, removed the Update Context variables
  • WarrenBelz Profile Picture
    153,599 Most Valuable Professional on at
    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
    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);
  • Suggested answer
    Garima_PowerPlatform Profile Picture
    170 on at
     
    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})
    )
     
  • WarrenBelz Profile Picture
    153,599 Most Valuable Professional on at
    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

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 450

#2
WarrenBelz Profile Picture

WarrenBelz 377 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 311 Super User 2025 Season 2

Last 30 days Overall leaderboard