Forum Discussion

oscarca's avatar
oscarca
Icon for Helper I rankHelper I
2 years ago

How to create a YTD aggregation as a calculated column in Power BI ?

Hello Community,
I am trying to create a calculated column in a calculated table that aggregates Invoiced Quantity year to date for each Period in the table. So for example Period 202307 should summarize the values between 202301 and 202307 and 202308 should summarize the values between 202301 and 202308 etc. But I don't seem to get the logic to work quite properly because If I choose the Period 202307 it will only return the value for that month and not the sum of 202301 - 202307.
My example consists of one fact table "Fact_sales" and two dimension tables "Dim_Calendar" and Dim_Item:

CalculatedTable = 
SUMMARIZE (
    Fact_sales,
    Dim_Calendar[Fiscal period],
    Dim_Calendar[Fiscal year],
    Dim_Customer[Customer],
    Dim_Item[Item number],
    "YTD_InvoicedQty",
        CALCULATE (
            SUM ( Fact_sales[Invoiced quantity - basic U/M] ),
            FILTER (
                ALL ( Dim_Calendar ),
                Dim_Calendar[Fiscal year] = VALUES(Dim_Calendar[Fiscal year]) &&
                Dim_Calendar[Fiscal period] <= MAX(Dim_Calendar[Fiscal period])
            )
        )
)

All help are appreciated!
Best regards,
Oscarca

2 Replies