+ Reply to Thread
Results 1 to 3 of 3

Power Query, Transform Column by values in another columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    649

    Power Query, Transform Column by values in another columns

    Hi,
    I've attached a work book showing in excel what I would like to do in power query,
    I have a budges for each row, and want to allocate it between each item in that row, so if A1 = 3 , B1 = 2 , A1 = ( Budget / 5 ) * 3

    so;
     List.Accumulate ( listA, Source, (S,C)=>  
                                                         Table.TransformColumns( S, { C, (A)=> List.Count(  Text.Split(A,","))  } ))
    Gives the number of items in each cell, I can then sum these in addcolumns and divide

    Table.AddColumn(Custom1, "allocation", each Number.Round  (  [Budget] /   List.Sum ( { [DepC],[DeptA], [DeptD], [DeptB]} ),2),type number )
    I then need to multiply this by the number in each cell by this, I hope the excel table will show exactly what I'd like to do.

    I have thought about using addcolumns 'standard' multiply' ? the query accerAllocation is the one I've got furthest with so far.

    Richard.
    Attached Files Attached Files
    Last edited by Dicken; 06-29-2023 at 07:57 AM. Reason: forgot attachment

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,300

    Re: Power Query, Transform Column by values in another columns

    You could do something like this:

    let
        Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Area", "Budget"}, "Attribute", "Value"),
        AddItemCount = Table.AddColumn(#"Unpivoted Other Columns", "ItemCount", each List.Count(Text.Split([Value],","))),
        #"Added Custom" = Table.AddColumn(AddItemCount, "AddBudgetShare", each [Budget]*[ItemCount]/List.Sum(Table.SelectRows(AddItemCount, (a)=> a[Area]=[Area])[ItemCount])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value", "ItemCount"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "AddBudgetShare", List.Sum)
    in
        #"Pivoted Column"
    Anyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    649

    Re: Power Query, Transform Column by values in another columns

    Thanks,
    I had a few failed attempts at re pivoting, as I'd only removed one column and it kept messing things up,
    I shall hang on to this for future reference.
    RD

+ 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] Power Query Transform multiple columns
    By Dicken in forum Office 365
    Replies: 2
    Last Post: 05-27-2023, 11:11 AM
  2. Power Query Multiply column in transform
    By Dicken in forum Office 365
    Replies: 1
    Last Post: 04-11-2023, 10:00 AM
  3. [SOLVED] Transform data in Power Query
    By no_Fate in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2022, 06:25 AM
  4. Power query - transform help
    By N3CREN in forum Excel General
    Replies: 0
    Last Post: 10-23-2020, 09:01 AM
  5. [SOLVED] Power Query transform help
    By ierosadopr in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-09-2019, 05:25 AM
  6. Replies: 1
    Last Post: 03-12-2019, 04:42 PM
  7. Power Query (Get & Transform) on Mac
    By SHI.NL in forum Excel General
    Replies: 2
    Last Post: 05-18-2018, 09:24 AM

Tags for this Thread

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