I just spent way too long trying to figure out how to solve this problem, so I'm posting my solution for posterity.
Problem: I have a 50+ page document and I added a text field on the master for pagination, e.g. "01 / 50" or "Page 1 of 50". I used Type > Insert Special Character > Markers > Current Page Number for the first number and Type > Text Variables > Insert Variable > Last Page Number for the second number. This works fine and dandy until you add sections. When I added sections (by context-clicking on the page in the pages panel and then choosing Numbering & Sections Options... and checking Start Section it totally screws up the total document page count (i.e. Last Page Number) for each section. I started getting "01 / 06" instead of the "01 / 50" which I expected.
Before I post how I solved this problem I'm going to include some of the web search strings I used in case that helps some future soul avoid the time I spent looking for the answer. Here are the searches I did that didn't quite return the information I needed:
There was good information in these searches, but none of it helped me quickly identify the real solution, which I will post as a reply here shortly.
To solve the problem I actually had to go into Type > Text Variables > Define. Select Last Page Number and tap the Edit button. Notice the dropdown titled Scope and see that it's set to Section by default. Change the scope to Document and the problem is solved; page count now reads "01 / 50" instead of "01 / 06".
THANK YOU. I just wasted a lot of time setting up my page numbering system (which was stupidly complicated) and thought I was done until I saw my Page X of XX was screwed up because of the sections I created. You just saved me from going down another rabbit hole.
And fyi the search words I entered to find this page were:
indesign "last page number" document section
Thank you again for posting this!!!!