+ Reply to Thread
Results 1 to 14 of 14

Rearranging Data based on dates

  1. #1
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Rearranging Data based on dates

    Hi,

    Im trying to rearrange a table to a different format based on dates. Can use either Excel 365 solution or Power Query
    Desired results attached
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Rearranging Data based on dates

    Hi. This one caused some head pain!

    Try this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Rearranging Data based on dates

    Sub-formula B could also be tidied a bit:

    B,BYROW(DROP(A,,2),LAMBDA(z,MAX(z)))

    so there's only ONE range (subformula A) to adjust.

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Rearranging Data based on dates

    In Power Query you can do it pretty easily like this

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        
    types Table.TransformColumnTypes(Source,{{"Month"type date}}),
        
    lstPlan Table.AddColumn(types"lPlan"each {1..[Plan]}),
        
    lstActual Table.AddColumn(lstPlan"lActual"each  {1..[Actual]}),
        
    expPlan Table.ExpandListColumn(lstActual"lPlan"),
        
    expActual Table.ExpandListColumn(expPlan"lActual"),
        
    repNulls Table.ReplaceValue(expActual,"a","b",(x,y,z)=>  ?? ,{"lPlan""lActual"}),
        
    Plan Table.AddColumn(repNulls"Plan_"each if [lPlan] < [lActual]  then "No Plan" else [Month]),
        
    Actual Table.AddColumn(Plan"Actual_"each if [lPlan] > [lActual]  then "No Actual" else [Month]),
        
    result Table.RemoveColumns(Actual,{"Month""Plan""Actual""lPlan""lActual"})
    in
        result 
    Attached Files Attached Files
    Last edited by JEC.; 03-16-2024 at 08:16 AM.

  5. #5
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    Hi Glenn, Awesome work, appreciate your effort.
    Ran into some error when input values were changed, hope it should be an easy fix
    Attached sheet
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    Hi JEC,

    Nice work! I would also like to have a query solution but there seems to be some glitches when the input values are changed
    For eg I changed D3 to 5 and E3 to 2 and refreshed the query, the output table was giving total 10 rows instead of 5
    Also, no.of plan and actuals were also wrong.

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Rearranging Data based on dates

    Try it now.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    Hi Glenn,

    Works perfect now. Thanks a lot

  9. #9
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Rearranging Data based on dates

    Ok try this, even shorter

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        
    types Table.TransformColumnTypes(Source,{{"Month"type date}}),
        
    lstActual Table.AddColumn(types"tList"each  {1..List.Max({[Actual],[Plan]})}),
        
    expList Table.ExpandListColumn(lstActual"tList"),
        
    Plan Table.AddColumn(expList "Plan_"each if [Plan] < [tList]  then "No Plan" else [Month]),
        
    Actual Table.AddColumn(Plan"Actual_"each if [Actual] < [tList]  then "No Actual" else [Month]),
        
    result Table.RemoveColumns(Actual,{"Month""Plan""Actual""tList"})
    in
        result 
    Last edited by JEC.; 03-17-2024 at 06:34 AM.

  10. #10
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    This works, JEC !!
    Thanks a lot

  11. #11
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    Hi Glen/JEC,

    Sorry to state additional requirement at this stage but I realized that a modification is required for my data to benefit further analysis.
    The requirement is that any "No Actual" cells for an ID should be filled using actuals from the following ID ( if available)
    This is to fill out all the Plan before actual for any subsequent IDs is spread out against the next plan


    Attaching sheet with desired results
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Rearranging Data based on dates

    How about this?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Rearranging Data based on dates

    Here the PQ version

    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    07-12-2015
    Location
    Dubai,UAE
    MS-Off Ver
    Office 365
    Posts
    425

    Re: Rearranging Data based on dates

    Hi windknife and JEC,

    Thanks for your response

    The actual should be distributed only if there is a plan ( Attaching sheet with desired results)
    In this sheet, plan for Jan is 10, total for actuals for Jan, Feb, Mar is 9 so they are distributed against Jan
    For the remaining 1 plan, is taken from next available actual - Apr and the remaining actuals for Apr are distributed against Apr plan
    Attached Files Attached Files

+ 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] Rearranging Data Based on Delimiter
    By chullan88 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-25-2024, 07:23 AM
  2. Rearranging dates entered as text into usable dates
    By Lockie in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-27-2023, 07:28 AM
  3. rearranging dates
    By revdjembo in forum Excel General
    Replies: 4
    Last Post: 06-09-2021, 03:23 PM
  4. [SOLVED] Rearranging the data set based on multiple rules.
    By sulin360 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-17-2013, 10:33 AM
  5. Rearranging Production Data According to Dates
    By weelongtanwl in forum Excel General
    Replies: 1
    Last Post: 09-12-2012, 09:53 AM
  6. [SOLVED] Rearranging an time series with missing dates
    By bafuncio in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-09-2012, 04:29 PM
  7. Rearranging Cells Based on Letter Case
    By imtimwhoareyou in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-10-2008, 06:26 PM

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