Forum Discussion

Abourard's avatar
Abourard
New Member
8 months ago
Solved

Power Query: Custom column to sum revenues for remaining months based on selected month number

I am working in Power Query and need to create a custom column to support a simple forecast calculation.   I have monthly revenue data with a month number column (1–12). Based on a selected month n...
  • Olufemi7's avatar
    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
        Result

     

    2. 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.