• 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

Power Query : Add a custom column to get YTD value and Custom column to have Forecast value|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Power Query : Add a custom column to get YTD value and Custom column to have Forecast value|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 QueryPower Query : Add a custom column t…
sp_PrintTopic sp_TopicIcon
Power Query : Add a custom column to get YTD value and Custom column to have Forecast value
Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
1
February 19, 2023 - 6:00 am
sp_Permalink sp_Print

Dear All,

I would really appreciate your help.

I have a file; the data is imported via connection only in Power Query. I have many columns (Text and monthly data) but most important ones are the monthly columns. I want to have a custom column for YTD, which will sum up all these columns. Then I want to have another YTD column where it will divide the YTD value by the no of months I have and multiply by 12.

So, suppose we have two months data (April and May).

April = £1,000
May - £3,000

I want a custom column for YTD and the result should be = £4,000
Another custom column for Forcast and the result should be = (£4,000/2) x 12 = £24,000

and when I have in the next month 3 months data (April, May and June)

It should sum up all three months, and for the forecast, it should divide by 3 and multiply by 12 automatically.

Your help would be really appreciated.

Please see the attached picture.

Monthly-Datas.jpgImage Enlarger

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
2
February 19, 2023 - 4:53 pm
sp_Permalink sp_Print sp_EditHistory

See if the attached example does what you need. By the way, it assumes you have one text column and all others contain the monthly data.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
3
February 19, 2023 - 7:27 pm
sp_Permalink sp_Print

Hi Riny,

Many Thanks for your reply and for coming up with the solution.

Yes, this is exactly what I want, but on my file, it's not working. I managed to understand all the steps but 2nd step "Data" (what is happening in this step) and the 3rd step "Count", I could not apply properly (not sure what -1 means).

Could you please have a look at the attached file?

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
4
February 19, 2023 - 8:10 pm
sp_Permalink sp_Print

Data is nothing more than the "TransformColumnType" step renamed to something more friendly. I used the step name later on when I do a Merge. but now I changed after seeing your file, to make it more dynamic.

Then the Count step is a manually added step that counts the number of columns int he table and deducts 1 to not count the first column. Since your table has 9 text columns you need to deduct 9 here.

And the grouping need to be done on column that contains the unique identifier for each row, so I changed the Name column as a n example.

See attached. come back her if you get stuck.

I didn't load the table back to Excel as the file would become to big to upload here.

Avatar
Alan Sidman
Steamboat Springs, CO
Member
Members


Trusted Members
Level 0
Forum Posts: 130
Member Since:
October 18, 2018
sp_UserOfflineSmall Offline
5
February 20, 2023 - 6:38 am
sp_Permalink sp_Print

crossposted:  https://chandoo.org/forum/thre.....lue.51358/

 

Please read:  https://excelguru.ca/a-message.....s-posters/

The following users say thank you to Alan Sidman for this useful post:

Riny van Eekelen
Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
6
February 21, 2023 - 8:14 am
sp_Permalink sp_Print

Thank you for your explanation and for providing the solution. It is working exactly the way I wanted.

Sorry I cross-posted this question at chandoo as well. I have provided your solution and explanation, so no one else will spend time resolving my query.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
7
February 21, 2023 - 8:22 am
sp_Permalink sp_Print

I have another query related to the same file, but I have added two more columns this time. Column A is for the FY and column E is for lookup value. There is another sheet where the lookup formula will look and pick the values from.

 

What I am looking to do is via Power query - first in column A search for the most recent year (in this case 22-23 is the most recent year) and then perform the vlook up only for this particular year and not for other years.

Is this possible in Power Query?

 

Your help would be really appreciated.

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
8
February 21, 2023 - 3:52 pm
sp_Permalink sp_Print

I guess that's possible, but to save me from having to guess how your tables and data are structured and exactly what to look-up from where, please upload another file with let's say 50 rows of representative date (though non-confidential) with the expected results in it.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
9
February 22, 2023 - 7:32 pm
sp_Permalink sp_Print

Thank you Riny.

Please see the attached file with the expected results.

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
10
February 22, 2023 - 8:01 pm
sp_Permalink sp_Print

I like to keep thing simple. And because you don't work with real dates, I added a column to the lookup table for the year "22-23". Then you can easily do a merge based on the Year and Acc columns from the Trend table,

See if you can follow the steps in the attached file.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
11
February 22, 2023 - 10:38 pm
sp_Permalink sp_Print

The problem is the Lookup table values can belong to any of the FY, e.g: 20-21, 21-22, 22-23. So we cannot allocate FY to it by creating a new column for FY. I am keen to avoid this step.

Is there any other way possible?

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
12
February 22, 2023 - 10:47 pm
sp_Permalink sp_Print

Sorry, but I don't understand. I merely followed your example. How would you do the lookup in Excel for, let's say two out of three years? Perhaps you can give a more complete example that contains all possible situations.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
13
February 26, 2023 - 3:21 am
sp_Permalink sp_Print

Thank you for your reply and my apology for the late response.

I have now understood the file is working correctly as per my need, but there is one problem. When more data is added to the sheet, we will have 23-24 and 24-25 and so on. 

I want to make it dynamic, so it picks the latest FY dynamically and then applies the lookup but the data for other years should remain there in this case for year 22-23.

For example, we are in FY 22-23 and pulling the data using the query created by you successfully and now we are in 23-24; the lookup should happen dynamically for FY 23-24 and stop for 22-23, and whatever the data it has pulled for year 22-23 all rows should stay.

I hope the above makes sense.

Thank you very much for looking into my problem and putting your time and effort into finding the solution. 

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
14
February 26, 2023 - 3:45 pm
sp_Permalink sp_Print

Okay! Since you work with texts rather than real dates you can't just scan the Year column for the "latest date". I added a small query that just takes the Year column, sorts it in descending order and then drills down to the entry in first row, creating a variable called MaxYr.

I removed the Yr column(that I had manually added in Excel) from the look-up table but now dynamically add it in PQ based on the variable MaxYr. Then the other query works the same.

So, when you have Year "23-24" in the data, it will be picked up as the MaxYr. It will add the column Yr to the look-up table filled with "23-24" and merge (i.e. lookup) only rows for the Year "23-24".

Perhaps not the most elegant solution, but it works and it's easy to follow.

Avatar
Hanan Khan
Member
Members
Level 0
Forum Posts: 9
Member Since:
February 19, 2023
sp_UserOfflineSmall Offline
15
February 27, 2023 - 12:55 am
sp_Permalink sp_Print

I am happy as long as the query is working and the desired outcome is achieved.

I cannot see any attached file. Is there any? If you could attach it again please.

 

Many Thanks. 

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


Trusted Members

Moderators

Power BI
Level 0
Forum Posts: 440
Member Since:
January 31, 2022
sp_UserOfflineSmall Offline
16
February 27, 2023 - 1:24 am
sp_Permalink sp_Print sp_EditHistory

Oh! Sorry about that. It seems I missed the Upload button myself this time 🙁

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Mynda Treacy
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Len Matthews
Kristine Arthy
Michelle Neven
Andrew Kuhn
Angela Paul
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27205

 

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