+ Reply to Thread
Results 1 to 13 of 13

Create a data set by extracting data from another data set? Probably complicated...

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Create a data set by extracting data from another data set? Probably complicated...

    Hi all,

    I have access to daily data in a spreadsheet. Stock market data. The first challenge is that not every week starts on a Monday and not every week ends on a Friday. I'm sure 90 % starts on a Monday and ends on a Friday; but certainly not all.

    Each day is a row in my data set.

    From this, I want to summarize each week also in a row in a similar fashion.

    The Open value will always be from the first day of the week.

    The High value will be the maximum of the High column for each week.

    The Low value will be the minimum of the Low column for each week.

    The Close value will always be from the last day in the week.

    Additionally, I'm interested in knowing on which day of the week the High and Low is found.

    Is this possible without too much trouble?

    If not, I may have to see if my data provider could provide this data. Actually, I already have access to that. The problem is that with weekly data, I won't know on which day of the week the High/Low is found.

    Thanks in advance for any pointers! Attaching screenshot below and also workbook.

    Best regards,

    Elijah

    1.png
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Since you have Office 365, I'd recommend using Power Query (Get & Transform) to perform data transformation.

    First select your data table and go to Data tab -> Get & Transform Data -> From Table/Range.

    Go in to Query Editor.

    Select "SeriesTable" in Queries pane (left most pane) and copy & paste.

    In the pasted query, in Applied steps pane, select Source. Then add custom column named "Year" with following:
    Please Login or Register  to view this content.
    Then change Year column's data type to Whole Number (Int64.Type).

    Select Week column and Group By. And go to Advanced option.

    Set up like image below.
    0.JPG

    Now, go back to original query and add "Year" column like you did above.
    Add new custom column named "WeekDay" as following:
    Please Login or Register  to view this content.
    Set the data type to Text.

    Go back to the pasted query.

    Now you will merge original query into pasted query multiple times using different key columns (i.e. similar to Lookup).

    However, I noticed that there are several duplicate records using your logic.

    Ex: Week 11, Year 2013. Has two dates with identical Low value. This will create 2 rows (1 for Monday and another for Tuesday).
    1.JPG

    There are 2 other week that has similar issue. How should this be handled?

    EDIT: Woops, had missed that you already had Day column showing Weekday. You can ignore that step
    Last edited by CK76; 07-23-2019 at 01:01 PM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Wow! Thank you so much, CK76!

    This is highly appreciated.

    However, I noticed that there are several duplicate records using your logic.
    There are 2 other week that has similar issue. How should this be handled?
    I'm suprised there are only 2.

    In my mind, the first occurence of each should be the valid one. In your example - that would be Monday.

    Maybe I missed it not having gone through your example yet myself, but were you able to extract which day in the week have the high/low value?

    Thanks again.

    Elijah

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    I hadn't explained that part. Since how it should be handled would be different according to logic to handle duplicate low/high values.

    Now to continue where I left off.

    In the pasted query. Combine -> "Merge Queries". For all merge operation you'll by using Left Outer Join.

    1. Using "StartDate" from pasted query and "Date" from original merge original into pasted query.
    2. Expand "Prior Close" & "Open" from the resulting column.
    3. Using "EndDate" from pasted query and "Date" from original merge original into pasted query.
    4. Expand "Close" from the resulting column.
    5. Using "Week", "Year" & "Low" from pasted query (select in sequence while holding CTRL key), select same columns in original table. Making sure to select columns in same sequence.
    0.JPG
    6. Expand the "Date" column.
    7. Select all but the "Date" column and Group By. Use "LowDate" as column name, Operation = "Min", on "Date" column. This will eliminate duplicated row and return min date for low.
    8. Repeat step 5 to 7, but this time using "High" column instead of "Low". (I left it as Min for "Date", but you can change it to Max to get last high date in week).
    9. Now add custom column "Weekday Low".
    Please Login or Register  to view this content.
    10. Add "Weekday High"
    Please Login or Register  to view this content.
    11. Change data type to text for both columns. Drop unnecessary columns, reorder columns and load both queries as connection only.
    12. Back in worksheet, click on "Queries & Connections". Right click on the pasted query and select "Load To" and load to desired location.

    See attached.
    Attached Files Attached Files

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Oh, this is just one method to do it in PowerQuery.

    I went this route as it requires minimal amount of custom function and/or complex steps and majority of operation are done using GUI.

    Other methods include...
    - Loading data to DAX and using PowerPivot and measures to perform aggregation.
    - Using List.Generate() and/or List.Accumulate.

  6. #6
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Wow, CK76,

    This is simply amazing. I'm humbled by both your helpfulness and expertise on the subject. Thank you so much!

    I was only able to take a quick look at the sheet you provided, but it looks great to me. I will try to re-create it from scratch following your detailed instructions later tonight and report back.

    - - -

    I have an additional related question:


    Would it be possible to use the same dataset to create additional datasets using 'partial weeks/rows'?

    A partial row/week would simply be a row which consists of data from only parts of the week, but always starting on Monday.

    Dataset 1 - Monday: This row would only contain Monday and consists of one day only, so I have this one already in my original dataset.

    Dataset 2 - Monday - Tuesday

    Dataset 3 - Monday - Wednesday

    Dataset 4 - Monday - Thursday

    Dataset 5 - Monday - Friday: This would be the one you already helped me create spanning the entire week.


    The purpose of this is that I would want to consult for example dataset 3 at the end of Wednesday, filter similar days and then match those days/dates with dataset 5 and see if I can notice any predictive qualities by week end.

    If this is not possible with Power Query, I may be able to extract this information from my data provider. But Power Query is of course better if possible.

    Thanks in advance for your input.

    Best,

    Elijah

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Dataset 2 to 4, should it be in exactly same format as the sample I provided?
    I'd imagine it's possible. You'll need to add bit of dynamic calculation and variable or tow in advanced editor for query.
    Edit: Oh and it's more suited for Data Model and DAX to perform this sort of dynamic analysis on data set.

    But I'm having trouble envisioning partial week data giving predictive/forecasting trend of any value.

    If you have trouble with that part. I'd recommend starting another thread. And use descriptive thread title. Referencing this thread in the post.
    That way, it's easier for others using the forum to search for solutions and doesn't clutter this one.
    Last edited by CK76; 07-23-2019 at 02:00 PM.

  8. #8
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Quote Originally Posted by CK76 View Post
    5. Using "Week", "Year" & "Low" from pasted query (select in sequence while holding CTRL key), select same columns in original table. Making sure to select columns in same sequence.
    Attachment 633830
    6. Expand the "Date" column.
    7. Select all but the "Date" column and Group By. Use "LowDate" as column name, Operation = "Min", on "Date" column. This will eliminate duplicated row and return min date for low.
    Hi, again,

    I'm slowly working through your example and trying to understand your steps, but I got stuck on step 7.

    If I select all but the "Date" column and group by - I'm not able to find the column "Date" to perform "Min" on.

    Did I misread you somewhere...?

    2.png

    Beyond this - most of the steps seems understood, although some of it is above my head...

    Best regards and thanks again,

    Elijah

  9. #9
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Quote Originally Posted by CK76 View Post
    Dataset 2 to 4, should it be in exactly same format as the sample I provided?
    I'd imagine it's possible. You'll need to add bit of dynamic calculation and variable or tow in advanced editor for query.
    Edit: Oh and it's more suited for Data Model and DAX to perform this sort of dynamic analysis on data set.
    I think so, yes. But it depends on what's possible I suppose.

    Quote Originally Posted by CK76 View Post
    But I'm having trouble envisioning partial week data giving predictive/forecasting trend of any value.

    If you have trouble with that part. I'd recommend starting another thread. And use descriptive thread title. Referencing this thread in the post.
    That way, it's easier for others using the forum to search for solutions and doesn't clutter this one.
    It's hard to say if it can have any predictive value. I guess it's one of those things you never know before you try.

    I'm at least interested in testing it out and see what I can find.

    I will need help for sure. I'm already having trouble following your steps here on this task which probably is more basic.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Select first column in your data. Press and hold Shift, use mouse to select the last column before "Date" column.

    Alternately, go to advanced option, and add all the columns except "Date" column as Group column.

  11. #11
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Quote Originally Posted by CK76 View Post
    Select first column in your data. Press and hold Shift, use mouse to select the last column before "Date" column.

    Alternately, go to advanced option, and add all the columns except "Date" column as Group column.
    I probably botched something up along the way. I don't have a column named "Date" in the pasted query. Probably need to retrace my steps.

    4.png

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Ah should have specified that I unchecked option to use original as prefix when expanding.
    You can use SeriesTable.Date in your image.

  13. #13
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Create a data set by extracting data from another data set? Probably complicated...

    Quote Originally Posted by CK76 View Post
    Ah should have specified that I unchecked option to use original as prefix when expanding.
    You can use SeriesTable.Date in your image.
    Okay!

    Once again, thank you so much for this, CK76!

    I managed to retrace your steps just fine now. But, it would take me quite some time to be able to do so on my own.

    Many thanks.

    Elijah

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] extracting data from a complicated table
    By Diogo2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2019, 01:10 PM
  2. How can I create a macro for extracting data from multiple workbooks within a folder
    By surfing69 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 11:36 AM
  3. Replies: 2
    Last Post: 09-16-2013, 05:17 AM
  4. Replies: 0
    Last Post: 09-12-2013, 10:22 AM
  5. Extracting data from two tables to create a third.
    By Criterium in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-12-2010, 10:21 AM
  6. Extracting part of a data string to create a table
    By chris.howes in forum Excel General
    Replies: 0
    Last Post: 07-31-2007, 10:11 AM
  7. Extracting data from a client worksheet to create an invoice
    By Jacques E. Bouchard in forum Excel General
    Replies: 1
    Last Post: 05-08-2005, 03:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1