+ Reply to Thread
Results 1 to 6 of 6

Translating dynamic array formula for ranking into Power Query M code

  1. #1
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Translating dynamic array formula for ranking into Power Query M code

    Hi,

    I have the following formula (courtesy of Bo_Ry), which gives incrementally increasing rank numbers to rows in a table, with equal rank to duplicate rows:

    =LET(z,Table[Batch]&" | "&Table[Step Text]&" | "&Table[Control recipe],u,SORT(UNIQUE(z)),MATCH(z,u,)-MATCH(Table[Batch]&" | "&Table[Step Text]&" | "&"*",u,))+1

    Please see attached workbook with example.

    I am trying to achieve what this formula does by working with the data in Power Query. I have imported the table, and pasted values of the rank numbers, but I need an M code that does what the dynamic array function above does.

    Any suggestions?

    Best regards,
    Marbleking
    Attached Files Attached Files
    Last edited by Marbleking; 10-26-2021 at 08:58 AM.

  2. #2
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Translating dynamic array formula for ranking into Power Query M code

    Hi,

    I have also added an alternative rank formula using SUMPRODUCT and COUNTIFS, for information. See updated workbook.

    =SUMPRODUCT(($A$2:$A$30=$A2)*($B$2:$B$30=$B2)*($F$2:$F$30<$F2)/COUNTIFS($A$2:$A$30,$A$2:$A$30,$B$2:$B$30,$B$2:$B$30,$F$2:$F$30,$F$2:$F$30))+1

    I hope someone can solve this in Power Query.

    Regards,
    Marbleking
    Attached Files Attached Files

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Translating dynamic array formula for ranking into Power Query M code

    Hi,

    Power Query? Are you sure you don't mean within DAX? Power Query is intended for accessing and transforming data; it is not designed to perform calculations, especially complex ones as you have here. In general: import, shape and transform the data within Power Query, then perform calculations within DAX (using either measures or calculated columns added to your tables).

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Translating dynamic array formula for ranking into Power Query M code

    Hi XOR LX,

    I was hoping to achieve this through using M code in Power Query, because these rank numbers will be used to further transform some of the data into unique column headers, by combining and transposing a few of the columns, including these rank numbers. If the same is possible by using DAX in the data model, and create a column which then can be used in Power Query, that would be fine. But I'm fairly new to these concepts. Guidance appreciated.

    Regards,
    Marbleking

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Translating dynamic array formula for ranking into Power Query M code

    Try

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Table"]}[Content],
        
    AIndex Table.AddIndexColumn(Source"Index"01Int64.Type),
        
    Grouped Table.Group(AIndex, {"Batch""Step Text"}, {{"C"each Table.AddIndexColumn(Table.Group(_,{"Control recipe"},{"T",each _}),"Rank",1)  }}),
        
    ExpandedC Table.ExpandTableColumn(Grouped"C", {"T""Rank"}, {"T""Rank"}),
        
    ExpandedT Table.ExpandTableColumn(ExpandedC"T", {"Control recipe""Index"}, {"Control recipe""Index"}),
        
    Sorted Table.Sort(ExpandedT,{{"Index"Order.Ascending}}),
        
    RemovedColumns Table.RemoveColumns(Sorted,{"Index"})
    in
        RemovedColumns 
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    08-20-2011
    Location
    Oslo
    MS-Off Ver
    MS 365
    Posts
    245

    Re: Translating dynamic array formula for ranking into Power Query M code

    Thanks a lot, Bo_Ry! Great to see a solution for this.

+ 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. Power Query M Code formula to produce a detailed customers' ledge
    By sunboy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-23-2021, 07:45 AM
  2. Power Query with Dynamic Source
    By andrewc in forum Excel General
    Replies: 3
    Last Post: 12-10-2020, 03:55 AM
  3. [SOLVED] Ranking in Power Query via multiple columns
    By sparkyster in forum Excel General
    Replies: 6
    Last Post: 11-19-2020, 10:56 AM
  4. [SOLVED] Dynamic Array Formula Query - Dates
    By moglij in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2020, 06:34 PM
  5. [SOLVED] Power Query - excel formula translation into Power Query
    By afgi in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 02-19-2020, 03:38 AM
  6. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  7. [SOLVED] Power Query ranking multiple columns
    By rs1aj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-26-2019, 11:43 PM

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