Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hi. I am struggling to figure out how to create a running total of points by ID and by nonsequential date. This would include multiple months for a given ID to show progress over time. Any help is truly appreciated.
Solved! Go to Solution.
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc3LDYAwDAPQXXKulNqhpcxSdf81AKmfgOCY58iuVUCTIIhKKiNxHZQWZkDFcHPema93U/tm/vAxvJenvN+rqz1535SzvzwDFLfQTg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Points = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Points", Int64.Type}}),
ListOfIDs = List.Buffer(#"Changed Type"[ID]),
ListOfDates = List.Buffer(#"Changed Type"[Date]),
ListOfPoints = List.Buffer(#"Changed Type"[Points]),
//Function Start
fxGetCumTotal=(ListOfIDs, ListOfPoints)=>
let
FunctionResult = List.Generate(()=>[x=ListOfPoints{0},i=0], each [i]<List.Count(ListOfPoints), each [i=[i]+1, x=(if ListOfIDs{i}=ListOfIDs{[i]} then [x] else 0) + ListOfPoints{i}], each [x])
in
FunctionResult,
//Function End
Result = Table.FromColumns(Table.ToColumns(#"Changed Type")&{fxGetCumTotal(ListOfIDs, ListOfPoints)},Table.ColumnNames(#"Changed Type")&{"Running Total"})
in
Result
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc3LDYAwDAPQXXKulNqhpcxSdf81AKmfgOCY58iuVUCTIIhKKiNxHZQWZkDFcHPema93U/tm/vAxvJenvN+rqz1535SzvzwDFLfQTg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Points = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Points", Int64.Type}}),
ListOfIDs = List.Buffer(#"Changed Type"[ID]),
ListOfDates = List.Buffer(#"Changed Type"[Date]),
ListOfPoints = List.Buffer(#"Changed Type"[Points]),
//Function Start
fxGetCumTotal=(ListOfIDs, ListOfPoints)=>
let
FunctionResult = List.Generate(()=>[x=ListOfPoints{0},i=0], each [i]<List.Count(ListOfPoints), each [i=[i]+1, x=(if ListOfIDs{i}=ListOfIDs{[i]} then [x] else 0) + ListOfPoints{i}], each [x])
in
FunctionResult,
//Function End
Result = Table.FromColumns(Table.ToColumns(#"Changed Type")&{fxGetCumTotal(ListOfIDs, ListOfPoints)},Table.ColumnNames(#"Changed Type")&{"Running Total"})
in
Result
Vijay, thank you. This is what I was looking for. You're awesome!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
17 | |
9 | |
8 | |
7 | |
7 |