Forum Discussion

JD2325's avatar
JD2325
New Member
3 years ago

Average / YTD Help

Hi Everyone,

 

I am really struggling with calculating averages in Power BI and I'm not sure why. I am looking to re-create the following excel graph in Power BI:

I have two tables in my dataset 'Invoice Tracker' & 'Calendar'. I've set the relationship Many to One linking to my 'Invoice Tracker' [DateApproved] column. I also have in my 'Invoice Tracker' table [CostCategory] which are the different accounts, [Subtotal] which is the amount spent.

I'm looking to have multiple bar graphs like above showing the amount spent per account across month/year.What I'm really not sure of is how to get the average or YTD average. Ideally I would have the YTD average show as a consistent value across all months of that year within the data. So for 2022 show a YTD average as a consistent number, and then for 2023 show a different consistent number.

 

I've tried a few different measures and can't seem to get it right. In the example below I am trying to take my YTD Amount and divide by NumMonths but my NumMonths isn't working the way I would like, and I only want to show the most recent value in my visual.

 

Most Recent YTD Amount Average =
VAR CurrentYear = YEAR(MAX('Invoice Tracker'[DateApproved]))
VAR LastDateThisYear =
    CALCULATE(
        LASTDATE('Invoice Tracker'[DateApproved]),
        FILTER(
            ALL('Invoice Tracker'[DateApproved]),
            YEAR('Invoice Tracker'[DateApproved]) = CurrentYear
        )
    )
VAR NumMonths = DATEDIFF(DATE(CurrentYear, 1, 1), LastDateThisYear, MONTH) + 1
RETURN
    DIVIDE([YTD Amount], NumMonths)
 

1 Reply