Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin 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
Hi All,
I have below dataset and required output as attached. I need to rolling quarterly figure for Value for each combination of ID,Category,Sub Category and Type. For example, for Month Dec-24, combination of ID,Category,Sub Category and Type, I need to go back Oct-24,Nov-24 & Dec-24 and aggregate the Value.
| ID | Category | Sub Category | Type | Month | Value |
| 1 | AA | A | T1 | Sep-24 | 100 |
| 1 | AA | A | T1 | Oct-24 | 50 |
| 1 | AA | B | T2 | Nov-24 | 100 |
| 1 | AA | B | T2 | Dec-24 | 90 |
| 1 | AA | A | T1 | Sep-24 | 100 |
| 1 | AA | A | T1 | Oct-24 | 50 |
| 2 | AA | B | T2 | Nov-24 | 100 |
| 2 | AA | B | T2 | Dec-24 | 90 |
| 1 | AA | A | T1 | Sep-24 | 100 |
| 1 | AB | B | T2 | Oct-24 | 50 |
| 2 | AA | A | T1 | Nov-24 | 100 |
| 2 | AA | A | T1 | Dec-24 | 90 |
Solved! Go to Solution.
Hi @rob_vander2 Could you try this please After Loading the data to Power Query
Sort the Data:
Sort the table by ID, Category, Sub Category, Type, and Month in ascending order.
Create a Custom Column for Rolling Total:
If this post helped please do give a kudos and accept this as a solution
Thanks In AdvanceI don't know, you have to test it 😉
You can also try this one (I've just added one 0 as 4th argument of inner Table.Group), but you can notice the speed difference. This will work if your data is sturcutred as your sample.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0BBFAHALiBacW6BqZABmGBgZKsTrYlPgnl0CUmKKpcAKpMAISfvllOAyBK3FJTYYosYSoUAAyMTF2B5DhRiPCbsRUQn03OiEbj9ONcENwuxGuBMWNsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t, #"Sub Category" = _t, Type = _t, Month = _t, Value = _t]),
// You can delete this step when applying on real data.
ReplacedBlanks = Table.TransformColumns(Source, {}, each if Text.Trim(_) = "" then null else _),
ChangedType = Table.TransformColumnTypes(ReplacedBlanks,{{"Value", Int64.Type}}),
TransformedValue = Table.Combine(Table.Group(ChangedType, "ID", {{"T", each Table.Combine(Table.Group(_, {"ID", "Category", "Sub Category", "Type"}, {{"T2", (x)=> if x{0}[ID] = null then x else let a = Table.ToRecords(x) in Table.FromRecords(List.RemoveLastN(a, 1) & {List.Last(a) & [Value = List.Sum(x[Value])]}) , type table}}, 0)[T2]), type table}}, 0, (x,y)=> Byte.From(y is null))[T])
in
TransformedValue
Hi @rob_vander2, check this:
Output
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0BBFAHALiBacW6BqZABmGBgZKsTrYlPgnl0CUmKKpcAKpMAISfvllOAyBK3FJTYYosYSoUAAyMTF2B5DhRiPCbsRUQn03OiEbj9ONcENwuxGuBMWNsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t, #"Sub Category" = _t, Type = _t, Month = _t, Value = _t]),
// You can delete this step when applying on real data.
ReplacedBlanks = Table.TransformColumns(Source, {}, each if Text.Trim(_) = "" then null else _),
ChangedType = Table.TransformColumnTypes(ReplacedBlanks,{{"Value", Int64.Type}}),
TransformedValue = Table.Combine(Table.Group(ChangedType, "ID", {{"T", each Table.Combine(Table.Group(_, {"ID", "Category", "Sub Category", "Type"}, {{"T2", (x)=> if x{0}[ID] = null then x else let a = Table.ToRecords(x) in Table.FromRecords(List.RemoveLastN(a, 1) & {List.Last(a) & [Value = List.Sum(x[Value])]}) , type table}})[T2]), type table}}, 0, (x,y)=> Byte.From(y is null))[T])
in
TransformedValue
TransformedValue step explanation in steps:
I don't know, you have to test it 😉
You can also try this one (I've just added one 0 as 4th argument of inner Table.Group), but you can notice the speed difference. This will work if your data is sturcutred as your sample.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0BBFAHALiBacW6BqZABmGBgZKsTrYlPgnl0CUmKKpcAKpMAISfvllOAyBK3FJTYYosYSoUAAyMTF2B5DhRiPCbsRUQn03OiEbj9ONcENwuxGuBMWNsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t, #"Sub Category" = _t, Type = _t, Month = _t, Value = _t]),
// You can delete this step when applying on real data.
ReplacedBlanks = Table.TransformColumns(Source, {}, each if Text.Trim(_) = "" then null else _),
ChangedType = Table.TransformColumnTypes(ReplacedBlanks,{{"Value", Int64.Type}}),
TransformedValue = Table.Combine(Table.Group(ChangedType, "ID", {{"T", each Table.Combine(Table.Group(_, {"ID", "Category", "Sub Category", "Type"}, {{"T2", (x)=> if x{0}[ID] = null then x else let a = Table.ToRecords(x) in Table.FromRecords(List.RemoveLastN(a, 1) & {List.Last(a) & [Value = List.Sum(x[Value])]}) , type table}}, 0)[T2]), type table}}, 0, (x,y)=> Byte.From(y is null))[T])
in
TransformedValue
Hi @rob_vander2 Could you try this please After Loading the data to Power Query
Sort the Data:
Sort the table by ID, Category, Sub Category, Type, and Month in ascending order.
Create a Custom Column for Rolling Total:
If this post helped please do give a kudos and accept this as a solution
Thanks In AdvanceCheck out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 4 |