• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Pick up the last previous record's total is erroring (Using List.Range)|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Pick up the last previous record's total is erroring (Using List.Range)|Power Query|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryPick up the last previous record's …
sp_PrintTopic sp_TopicIcon
Pick up the last previous record's total is erroring (Using List.Range)
Avatar
Chris Mason

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
July 5, 2020
sp_UserOfflineSmall Offline
1
July 5, 2020 - 9:06 pm
sp_Permalink sp_Print

I am relatively new to PQ and don't want to do it in DAX (lack of understanding as to how to move between the 2, and the final result is an Excel Table), I feel that I am now getting absolutely no where. All I am trying to do is read the total from the previous record. I do not want to do another index and join, so I thought I would go for a list.range, but having looked it up I cannot for the life of me get it to work. Utter Despair!! The code I have tried (the column is called Calc). is below:

= Table.AddColumn(#"Reordered Columns", "Custom", each List.Range(Source[Calc],[Index.1]-1,1)) and I get a column of errors 

Expression.Error: The column 'Calc' of the table wasn't found.
Details:
    Calc

So I took out source and did the following:

= Table.AddColumn(#"Reordered Columns", "Custom", each List.Range({[Calc]},[Index.1]-1,1))

The first value shows the total for the current row and all the other values are blank. I was hoping to pick up the previous row. I expect the 1st value to be an error but the rest should work I would have thought

 

Please tell me what or where I am going wrong.

List-Range-Issue.pngImage Enlarger

Thank you in advance.[Image Can Not Be Found]

sp_PlupAttachments Attachments
  • sp_PlupImage List-Range-Issue.png (126 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1826
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
July 5, 2020 - 11:10 pm
sp_Permalink sp_Print sp_EditHistory

Hi Chris,

To get the previous row value, you have more options.

One of them is to add 2 index columns: one starting from 0, and the other one starting from 1.

Next step is to merge the current table with itself, with the 2 index columns set as keys (use one index for first table, and the second index for the second table)

This will create the offset of 1 row you need, you will be able to bring the previous row value into the current row, by expanding the Calc column from the merge.

But if you're after a running total, you're not on the right track, adding a column with the following formula might help:

=List.Sum(List.FirstN(#"Added Index"[Number],[Index]))
Avatar
Chris Mason

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
July 5, 2020
sp_UserOfflineSmall Offline
3
September 10, 2020 - 2:40 am
sp_Permalink sp_Print

Hi Catalin,

Apologies for not coming back earlier and thank you for taking the time to answer. I was not keen on indexing as this is slowing down PQ hugely. I ended up using the SUMIF in excel after running the extract. It worked as was simple. I was trying to do it all in PQ, but it was taking toooo much time. 

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: David du Toit
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 218
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Aminu Sule
Samuel Ramirez
Abdifatah Osman
mohad borhom
Abayomi Adedeji
Ganesh MVS
Gilbert Lemek
Ashleigh Farquharson
Jayz Luu
Fred Smith
Forum Stats:
Groups: 3
Forums: 24
Topics: 6364
Posts: 27829

 

Member Stats:
Guest Posters: 49
Members: 32346
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.