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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Learner1585
Helper I
Helper I

undefinedCrew another custom column to count how many times each row value occurs in power query

Hi,

 

I want to create a custom column to count how many times a specic row value occurs in a column.

I dont want to create a calculated column but a custom colum as a transformation step in power query only.

Below is the example of what i am looking for.

  1.  There is a column name UID
  2. I want to create another custom column where each row shows how many times the adjacent value occurs.

Learner1585_0-1697816730090.png

 

Below is how I would do this in excel.

 

Learner1585_1-1697816743183.png

 

thank you very much

1 ACCEPTED SOLUTION

Hi,
Thank you very much for your kind reply.

Pardon me for my follow up, but being not so pro , can I seek your help again on how to add your codes into my existing codes.

Learner1585_0-1697881049070.png

Should I just add your code after my last step " 

    #"Added Index" = Table.AddIndexColumn(#"Merged Columns1", "Index", 1, 1, Int64.Type)

 

  • PreviousStepName = <Your existing code here>,
    BufferedList = List.Buffer(PreviousStepName[4sector UID]),
    AddColumn = Table.AddColumn(PreviousStepName, "Count", each List.Count(List.Select(BufferedList, (l)=> l=[4sector UID])))

Thanks again

View solution in original post

4 REPLIES 4
ImkeF
Super User
Super User

Yes, exactly.
So the end of your code would look like so:


  #"Added Index" = Table.AddIndexColumn(#"Merged Columns1", "Index", 1, 1, Int64.Type),
BufferedList = List.Buffer(  #"Added Index" [4sector UID]),
AddColumn = Table.AddColumn(  #"Added Index" , "Count", each List.Count(List.Select(BufferedList, (l)=> l=[4sector UID])))
in
AddColumn

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

thank you @ImkeF 

ImkeF
Super User
Super User

Hi @Learner1585 ,
you can do it like so:

PreviousStepName = <Your existing code here>,
BufferedList = List.Buffer(PreviousStepName[4sector UID]),
AddColumn = Table.AddColumn(PreviousStepName, "Count", each List.Count(List.Select(BufferedList, (l)=> l=[4sector UID])))

For performance reasons, you are adding an intermediate step where you buffer the column that you want to search through in each row.
Then you add the column where you count the values that match the current row.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Hi,
Thank you very much for your kind reply.

Pardon me for my follow up, but being not so pro , can I seek your help again on how to add your codes into my existing codes.

Learner1585_0-1697881049070.png

Should I just add your code after my last step " 

    #"Added Index" = Table.AddIndexColumn(#"Merged Columns1", "Index", 1, 1, Int64.Type)

 

  • PreviousStepName = <Your existing code here>,
    BufferedList = List.Buffer(PreviousStepName[4sector UID]),
    AddColumn = Table.AddColumn(PreviousStepName, "Count", each List.Count(List.Select(BufferedList, (l)=> l=[4sector UID])))

Thanks again

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors