Forum Discussion
Power Query: Custom column to sum revenues for remaining months based on selected month number
- 8 months ago
Hello Abourard,
Try this M code in Power Query. It filters months greater than your selected month and sums their revenues. You can either use a parameter for one forecast point or calculate it row‑by‑row:
1. Using a parameter (single forecast point)
let Source = YourTable, SelectedMonth = 5, // or create a parameter RemainingMonths = Table.SelectRows(Source, each [MonthNumber] > SelectedMonth), SumRemainingRevenue = List.Sum(RemainingMonths[Revenue]), Result = Table.AddColumn(Source, "RemainingRevenue", each SumRemainingRevenue) in Result2. Row‑level calculation (each month forecasts the rest of the year)
Result = Table.AddColumn(Source, "RemainingRevenue", each List.Sum( Table.SelectRows(Source, (r) => r[MonthNumber] > [MonthNumber])[Revenue] ) )Use the parameter approach if you want one forecast based on a chosen month, or the row‑level approach if you want every month to show its own “remaining months” total.
Abourard Are you positive that you want this in Power Query? Because selecting something and having the calculation change dynamically sounds a lot like a measure and that is DAX. If this is Power Query, how is the user selecting the month, in a parameter or is it whatever month is in the current row?
Hi GeraldGEmerick the peried number will be selected from a slicer. Can i add a dax formula a power pivottable?
- GeraldGEmerick8 months ago
Memorable Member
Boubou78 OK, if it is a slicer, you would need to use a DAX measure. It would look something like the following:
Monthly Revenue = VAR _Date = SELECTEDVALUE( 'Table'[Date] ) VAR _Month = MONTH( _Date ) VAR _Year = YEAR( _Date ) VAR _Return = CALCULATE( 'Table'[Value], 'Table'[Year] = _Year, MONTH( 'Table'[Date] ) > _Month ) RETURN _Return