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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Add a row to count rows in power query

Hi - i am hoping someone can help.

 

I am attempting to add a custom column in power query for powerbi desktop. The code i have is below, but i am getting a total count (14271), not a count of the filtered rows as shown in the table below the code - any idea how what i am doing incorrectly?

 

= Table.AddColumn( #"Expanded List_for_Est_Dates", "EST_ROW_COUNT", (row) => let SourceTable = #"Expanded List_for_Est_Dates", FilteredTable = Table.SelectRows( SourceTable, each [Dates] = row[Dates] and [ProjectID] = row[ProjectID] and [DAPolyID] = row[DAPolyID] and [ProductionUnitID] = row[ProductionUnitID] ), RowCount = Table.RowCount(FilteredTable) in RowCount, type number )

 

Expected results

DateProjectIDDAPOLYIDPRODUCTIONUNITIDROW COUNT
1/1/20221015202
1/1/20221015202
1/1/20221220202
1/1/20221220202
1/5/20221015203
1/5/20221015203
1/5/20221015203
     

 

2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

= Table.Combine(Table.Group( #"Expanded List_for_Est_Dates",{"Dates","ProjectID","DAPolyID","ProductionUnitID"},{"n",each Table.AddColumn(_, "EST_ROW_COUNT", (x)=>Table.RowCount(_))})[n])

View solution in original post

Anonymous
Not applicable

Hi @Syndicate_Admin 

You can put the following code to advanced editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJS0lEyNAARpkDCyEApVod4OSOIMJFypnjMJEMuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, ProjectID = _t, DAPOLYID = _t, PRODUCTIONUNITID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"ProjectID", Int64.Type}, {"DAPOLYID", Int64.Type}, {"PRODUCTIONUNITID", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.RowCount(Table.SelectRows(#"Changed Type",(x)=>x[Date]=[Date] and x[ProjectID]=[ProjectID] and x[DAPOLYID]=[DAPOLYID] and x[PRODUCTIONUNITID]=[PRODUCTIONUNITID])))
in
    #"Added Custom"

Output

vxinruzhumsft_0-1696835981476.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Syndicate_Admin 

You can put the following code to advanced editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJS0lEyNAARpkDCyEApVod4OSOIMJFypnjMJEMuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, ProjectID = _t, DAPOLYID = _t, PRODUCTIONUNITID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"ProjectID", Int64.Type}, {"DAPOLYID", Int64.Type}, {"PRODUCTIONUNITID", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.RowCount(Table.SelectRows(#"Changed Type",(x)=>x[Date]=[Date] and x[ProjectID]=[ProjectID] and x[DAPOLYID]=[DAPOLYID] and x[PRODUCTIONUNITID]=[PRODUCTIONUNITID])))
in
    #"Added Custom"

Output

vxinruzhumsft_0-1696835981476.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

wdx223_Daniel
Super User
Super User

= Table.Combine(Table.Group( #"Expanded List_for_Est_Dates",{"Dates","ProjectID","DAPolyID","ProductionUnitID"},{"n",each Table.AddColumn(_, "EST_ROW_COUNT", (x)=>Table.RowCount(_))})[n])

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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