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
walnei
Helper III
Helper III

Countif POWER QUERY


Hello, could you help me.
I need to do in Power Query, a column with the total number of times a record appears in the key column. I need it to be in the power query and not in the dax.
It would be like a countif in excel

CONT.SE.png

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@walnei,

 

This works in my sample, maybe it will work for you?

 

RAND(1,10)
7
2
1
2
9
5
7
8
8
2
3
1
6
2
5
6
5
3
4
3
10
3
10
6
7
4
9
1
5
6

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\username\Desktop\Book99.xlsx"), null, true),
    Tbl_count_Table = Source{[Item="Tbl_count",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Tbl_count_Table,{{"RAND(1,10)", Int64.Type}}),
    
    // Group 'All Rows' in the UI interface generates #"Grouped Rows" see image below
    #"Grouped Rows" = Table.Group(#"Changed Type", {"RAND(1,10)"}, {{"GroupTables", each _, type table}}),
    
    // Counts the rows in the table from previous step
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "CountRows", each Table.RowCount([GroupTables]))
in
    #"Added Custom"

2.PNG

 

Forgot to add the result: You can just remove the column you don't need.

3.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

3 REPLIES 3
ChrisMendoza
Resident Rockstar
Resident Rockstar

@walnei,

 

This works in my sample, maybe it will work for you?

 

RAND(1,10)
7
2
1
2
9
5
7
8
8
2
3
1
6
2
5
6
5
3
4
3
10
3
10
6
7
4
9
1
5
6

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\username\Desktop\Book99.xlsx"), null, true),
    Tbl_count_Table = Source{[Item="Tbl_count",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Tbl_count_Table,{{"RAND(1,10)", Int64.Type}}),
    
    // Group 'All Rows' in the UI interface generates #"Grouped Rows" see image below
    #"Grouped Rows" = Table.Group(#"Changed Type", {"RAND(1,10)"}, {{"GroupTables", each _, type table}}),
    
    // Counts the rows in the table from previous step
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "CountRows", each Table.RowCount([GroupTables]))
in
    #"Added Custom"

2.PNG

 

Forgot to add the result: You can just remove the column you don't need.

3.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



@ChrisMendoza

 

Thank you. It worked for me. This way works great. tks for attention

Greg_Deckler
Super User
Super User

Hmm...invoking @ImkeF


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.