• 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

List dates within start date and end date as a list. Suggestions for doing the reverse|Power Query|Excel Forum|My Online Training Hub

You are here: Home / List dates within start date and end date as a list. Suggestions for doing the reverse|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 QueryList dates within start date and en…
sp_PrintTopic sp_TopicIcon
List dates within start date and end date as a list. Suggestions for doing the reverse
Avatar
Sylvain Pasquier

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 1, 2019
sp_UserOfflineSmall Offline
1
March 26, 2019 - 8:20 pm
sp_Permalink sp_Print

I am after some suggestions as to how one may be able to do this .  

Start date End date (Aus date formatformat) 

01/01/19 05/01/19

12/03/19 15/03/19

Using { Number.From([StartDate])..Number.From([EndDate]) } gives me a list

01/01/19

02/01/19

03/01/19

04/01/19

05/01/19

12/03/19

13/03/19

14/03/19

15/03/19

However if I have the one column list as the original data source how does one arrive to the 2 rows ( or indeed lots of rows)  of start date end date? Thus in reality doing the transformation in reverse !

Have thought of grouping by min max with an index column possibly with modulo in combination but have not been able to transform it.  

Any suggestions appreciated. Not necessarily looking for complex code - UI preferred as I'm not a coder/programmer but rather a data analyst .

Thanks in advance 

SP

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4515
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
March 26, 2019 - 8:33 pm
sp_Permalink sp_Print

Hi Sylvain,

Welcome to our forum!

I'm not clear on what your desired result is and what data you have to work with? Are you trying to identify the first and last dates in a consecutive range or are you trying to generate a list of dates that have gaps in them?

Perhaps you could re-word your question identifying what you have to work with and what you're desired result is?

Thanks,

Mynda

Avatar
Sylvain Pasquier

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 1, 2019
sp_UserOfflineSmall Offline
3
March 27, 2019 - 5:56 pm
sp_Permalink sp_Print

Hi Mynda, 

 

Pleased to be a participant.  I have attached a spreadsheet.  Essentially I have start dates and dates that I can convert to a list of days.  However I need to do the reverse. List of days transformed to start date and end date.

Indeed sometimes I need to prove (to someone else) that the transformation is correct.  That is to do it in reverse of what I have done originally.  Thanks for any suggestions!

 

Cheers SP

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1824
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
March 27, 2019 - 10:59 pm
sp_Permalink sp_Print sp_EditHistory

Hi Sylvain,

You can prove that without much pain... You can calculate the difference between all start-end dates, the total should be equal to the number of rows from expanded table, if they don't believe you, they can check row by row the entire table of results  :).

It can be done, but you have to create a logical set of operations for that:

-Sort by ID and Dates

-Add an Index column

-add a new column to return the Index number where there is a change in ID or there is a gap between current row date and next row date

-Fill up

-Group By ID and the custom Column, extracting Min and Max dates for that group.

let
Source = Excel.CurrentWorkbook(){[Name="Originaldata"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"List days", type date}}),
#"Sorted Rows1" = Table.Sort(#"Changed Type",{{"ID", Order.Ascending},{"List days", Order.Ascending} }),
#"Added Index" = Table.Buffer(Table.AddIndexColumn(#"Sorted Rows1", "Index", 0, 1)),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each try (if [ID]<>#"Added Index"[ID]{[Index]+1} or Number.From([List days])<>Number.From(#"Added Index"[List days]{[Index]+1})-1 then [Index] else null) otherwise [Index]),
#"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
#"Grouped Rows" = Table.Group(#"Filled Up", {"Custom", "ID"}, {{"min", each List.Min([List days]), type date}, {"max", each List.Max([List days]), type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Custom"})
in
#"Removed Columns"

See the attached file.

Avatar
Sylvain Pasquier

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 1, 2019
sp_UserOfflineSmall Offline
5
March 29, 2019 - 5:53 pm
sp_Permalink sp_Print sp_EditHistory

Hi Catalin,  Thank you for your detailed response.  Much appreciate the explanation of the theory behind this... The code is just the execution of this. In the end it is not complicated . I didn't have my "theory / process" right.   Thus I will have to keep this in mind.  Lesson learnt. Yes you are correct with the "double accrual accounting" check . Regardless I do know of someone who would indeed check 7000 lines by sight... Probably more ... Mmmm

Just to add that the 2 queries put together. . .from start date to end date becoming a list of days and then list days becoming rows of start date to end date ... would make the following happen if you ever needed to combine continuous periods as one:

Example being two rows ...

12/05/18 to 18/06/18

19/06/18 to 25/09/18

Thus the same as this one row ... 

12/05/18 to 25/09/18

(There is bound to be more elegant simpler coding than this. )

One could create it as a function ...

 

Cheers 

Sylvain 

PS. .. I'll have to think of something more challenging 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1824
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
March 30, 2019 - 8:06 pm
sp_Permalink sp_Print

That's what the example I prepared is doing: takes a 1 column list of dates, then combines them into a "From:...To:..." dates range.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Vishal Nevase, John Kobiela, Sue Hammond, Lia Ro, Malcolm Sawyer
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: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

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