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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
ovetteabejuela
Impactful Individual
Impactful Individual

Power Query | Countif equivalent Fixed Reference

Hi,

 

What is the correct syntax or a similar method to achieve a countif with a fixed reference at the first row

       =COUNTIF(M$1:$M3,M3)

As you can see this formula expands as the row progresses... but how do I do it in M?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

First add an index column. Next add a column that pulls the M column from the #"Added Index" step and use List.Select to pull all values matching M (of the current step). Use List.Count to count the number of rows. Now you can remove the INdex column. Query is below. 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlSK1YlWSgKTyWAyEYmEi8QCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [M = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1),
    AddCountIf = Table.AddColumn(#"Added Index", "CountIf", each List.Count(List.Select(List.FirstN(#"Added Index"[M],[Index]), (el) => el = [M]))),
    #"Removed Columns" = Table.RemoveColumns(AddCountIf,{"Index"})
in
    #"Removed Columns"

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

First add an index column. Next add a column that pulls the M column from the #"Added Index" step and use List.Select to pull all values matching M (of the current step). Use List.Count to count the number of rows. Now you can remove the INdex column. Query is below. 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlSK1YlWSgKTyWAyEYmEi8QCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [M = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1),
    AddCountIf = Table.AddColumn(#"Added Index", "CountIf", each List.Count(List.Select(List.FirstN(#"Added Index"[M],[Index]), (el) => el = [M]))),
    #"Removed Columns" = Table.RemoveColumns(AddCountIf,{"Index"})
in
    #"Removed Columns"

 

Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.