Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alfranco17
Advocate I
Advocate I

Find position in a list in Power Query.

Hi.

 

I have a list like the first two columns and need to get the fourth one:

File

Employee

Index

 

Number

First

Tom

1

1

Last one

Tom

2

2

Week 1

Clark

3

1

March

Clark

4

2

April

Clark

5

3

 

I found Table.SelectRows and Table.RowCount. So I thought I could use something like:

= Table.RowCount(Table.SelectRows(#"My table", each ([Employee] = "Clark" and [Index] < 4)))

 

I don't know how I could substitute "Clark" with "the value for [Employee] in this record" and 4 for "the value of [Index] in the current row".

Is there a way to tell Power Query to look for the value of the field in the current record?

Is there an easier way to do it? Maybe there is a function that does exactly this and I don't know about it.

Thanks!

Armando.

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"File", type text}, {"Employee", type text}}),
    Partition = Table.Group(#"Changed Type", {"Employee"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"File", "Index"}, {"File", "Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Partition",{"File", "Employee", "Index"})
in
    #"Reordered Columns"

Hope this helps.

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.