• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Reducing a Baselined Amount from two tables |Power Query|Excel Forum|My Online Training Hub

You are here: Home / Reducing a Baselined Amount from two tables |Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
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 QueryReducing a Baselined Amount from tw…
sp_PrintTopic sp_TopicIcon
Reducing a Baselined Amount from two tables
Avatar
Andy Sibbald

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
May 6, 2021
sp_UserOfflineSmall Offline
1
April 13, 2022 - 10:58 pm
sp_Permalink sp_Print sp_EditHistory

Hi All,

I'd like to pick your brains if I could?

I may be over complicating this - if so, please tell me as I am relatively new to Power Query.

 

I have annual leave data (hours) coming straight off the OLAP Cube from peoples timesheets but would like to incorporate the persons annual allowance and have it reduce automatically on a exported pivot table.

 

Many thanks in advance

 

Andy

sp_AnswersTopicSeeAnswer See Answer
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 202
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
2
April 14, 2022 - 4:40 am
sp_Permalink sp_Print

If I understand you correctly you want something like this:

let
 Source = Table.NestedJoin(Leave, {"Name"}, Allowance, {"Name"}, "Allowance", JoinKind.LeftOuter),
 #"Expanded Allowance" = Table.ExpandTableColumn(Source, "Allowance", {"Allowance"}, {"Allowance.1"}),
 // Group all rows to add index column per employee
 #"Grouped Rows" = Table.Group(#"Expanded Allowance", {"Name"}, {{"Group", each _, type table [Name=nullable text, Date=nullable date,             Hours=nullable number, Allowance.1=nullable number]}}),
 #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Group],"Index",1)),
 #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Group"}),
 #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Date", "Hours", "Allowance.1", "Index"}, {"Date", "Hours",     "Allowance.1", "Index"}),
 // Second index column is to force position of the list to get an accurate remaining allowance by employee
 #"Added Index" = Table.AddIndexColumn(#"Expanded Custom", "Index.1", 0, 1, Int64.Type),
 // Running total of hours
 #"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each List.Sum(if [Index]=1 then List.Range(#"Added Index"[Hours],[Index.1],[Index]) else List.Range(#"Added Index"[Hours],[Index.1]-([Index]-1),[Index]))),
 #"Inserted Subtraction" = Table.AddColumn(#"Added Custom1", "Subtraction", each [Allowance.1] - [Custom]),
 // Column to account for new allowances
 #"Added Conditional Column" = Table.AddColumn(#"Inserted Subtraction", "Allowance", each if [Index] = 1 then [Allowance.1] else #"Inserted   Subtraction"[Subtraction]{[Index.1]-1}),
 #"Removed Other Columns" = Table.SelectColumns(#"Added Conditional Column",{"Name", "Date", "Hours", "Allowance", "Subtraction"}),
 #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Subtraction", "Adjusted Allowance"}}),
 #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Name", type text}, {"Date", type date}, {"Hours", Int64.Type}, {"Allowance",   Int64.Type}, {"Adjusted Allowance", Int64.Type}})
in
 #"Changed Type"

sp_AnswersTopicAnswer
Answers Post
Avatar
Riny van Eekelen
Örnsköldsvik, Sweden
Moderator
Members


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 441
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
3
April 14, 2022 - 7:05 pm
sp_Permalink sp_Print

As a variant, this code will produce a summary by person (Name, Allowance, Leave Taken and Balance).

let
Source = Excel.CurrentWorkbook(){[Name="Allowance"]}[Content],
Merge = Table.NestedJoin(Source, {"Name"}, Leave, {"Name"}, "Leave", JoinKind.LeftOuter),
AddedCustom = Table.AddColumn(Merge, "Leave Taken", each List.Sum ( Table.Column ( [Leave], "Hours" ) )),
Subtract = Table.AddColumn(AddedCustom, "Balance", each [Allowance] - [Leave Taken], type number),
Remove = Table.RemoveColumns(Subtract,{"Leave"})
in
Remove

Screenshot-2022-04-14-110238.pngImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage Screenshot-2022-04-14-110238.png (9 KB)
Avatar
Andy Sibbald

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
May 6, 2021
sp_UserOfflineSmall Offline
4
April 14, 2022 - 8:10 pm
sp_Permalink sp_Print sp_EditHistory

Error.PNGImage Enlarger

Works a treat Jessica/Riny, thank you.

 

Was this created in 365? Tried to step it through in edit and got errors. We are currently still using 2019.

 

Andy

sp_PlupAttachments Attachments
  • sp_PlupImage Error.PNG (38 KB)
  • sp_PlupImage Error.PNG (38 KB)
  • sp_PlupImage Error.PNG (38 KB)
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 202
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
5
April 15, 2022 - 8:45 am
sp_Permalink sp_Print

Mine was, yes. With that error the just take out the last arguement.

 #"Added Index" = Table.AddIndexColumn(#"Expanded Custom", "Index.1", 0, 1, Int64.Type),

That is just assigning the type whole number and not essential to setting up the index column.

Avatar
Andy Sibbald

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
May 6, 2021
sp_UserOfflineSmall Offline
6
April 15, 2022 - 7:57 pm
sp_Permalink sp_Print

Nice one Jessica.  Many thanks for your help. 

 

Andy

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, Nada Perovic, Andrew Er
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27279

 

Member Stats:
Guest Posters: 49
Members: 31903
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.