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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
micjensen
Frequent Visitor

Accumulate Row count Power Query Editor + DAX

Hi

I have a very simple data table with a unique perosn ID and a date stamp. What i want to do is to create a column that indicates the accumulated row count for each unique person id - i don't want to create a measure, but a column.

Below is my Data table and the other picture includes the column that i want to create. I would be very grateful if anybody would have the solution in DAX and in power query editor as well 🙂

Thx a lot in advance.


micjensen_0-1674144290195.png

micjensen_1-1674144398011.png

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @micjensen ,

 

In Power Query you can group the table with the All Rows operation then add an index to the nested tables:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1AciIwMjY6VYnWglJxxCRihCzpiqHHGowiJkjGm8MaZZWFSZIIRiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PersonID = _t, Date = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"PersonID", type text}, {"Date", type date}}),
    sortRows = Table.Sort(chgTypes,{{"PersonID", Order.Ascending}, {"Date", Order.Ascending}}),
    groupPersonID = Table.Group(sortRows, {"PersonID"}, {{"data", each _, type table [PersonID=nullable text, Date=nullable date]}}),
    addNestedIndex = Table.TransformColumns(groupPersonID, {"data", each Table.AddIndexColumn(_, "Count", 1, 1)}),
    expandNestedData = Table.ExpandTableColumn(addNestedIndex, "data", {"Date", "Count"}, {"Date", "Count"})
in
    expandNestedData

 

BA_Pete_0-1674145675670.png

 

 

For DAX, I would first sort your rows by [PersonID] and [Date] and add an index column IN POWER QUERY.

Then the following should work:

Count =
CALCULATE (
    COUNT(yourTable[PersonID]),
    ALLEXCEPT(yourTable, yourTable[PersonID]),
    yourTable[Index] <= EARLIER(yourTable[Index])
)

 

BA_Pete_1-1674146093815.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @micjensen ,

 

In Power Query you can group the table with the All Rows operation then add an index to the nested tables:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1AciIwMjY6VYnWglJxxCRihCzpiqHHGowiJkjGm8MaZZWFSZIIRiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PersonID = _t, Date = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"PersonID", type text}, {"Date", type date}}),
    sortRows = Table.Sort(chgTypes,{{"PersonID", Order.Ascending}, {"Date", Order.Ascending}}),
    groupPersonID = Table.Group(sortRows, {"PersonID"}, {{"data", each _, type table [PersonID=nullable text, Date=nullable date]}}),
    addNestedIndex = Table.TransformColumns(groupPersonID, {"data", each Table.AddIndexColumn(_, "Count", 1, 1)}),
    expandNestedData = Table.ExpandTableColumn(addNestedIndex, "data", {"Date", "Count"}, {"Date", "Count"})
in
    expandNestedData

 

BA_Pete_0-1674145675670.png

 

 

For DAX, I would first sort your rows by [PersonID] and [Date] and add an index column IN POWER QUERY.

Then the following should work:

Count =
CALCULATE (
    COUNT(yourTable[PersonID]),
    ALLEXCEPT(yourTable, yourTable[PersonID]),
    yourTable[Index] <= EARLIER(yourTable[Index])
)

 

BA_Pete_1-1674146093815.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi Pete

Thanks a lot for your explanatory reply. Much appreciated 🙂 !!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.