Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bjw210
Frequent Visitor

Chart YTD for multiple years from monthly data

I have a data set with monthly sales data that I'm trying to chart in a YTD view. If I have only one "scenario" a year I can use the year in the legend and it would work perfectly. However, I have multiple scenarios (Actuals, budget, forecast, etc) that can be in a given year. In the image below, the top left is MTD, the top right is YTD and you can see that the 2021 Actuals series no longer shows up on this chart (presumably because I'm using the TotalYTD function and 2022 is the latest year in the data). The formula works and calculates the right amounts based on the numerical table below the charts as long as it can pass the year, then the year scenario to the calculation. Any ideas on which measure would make all scenarios from each year show up in the YTD chart?
bjw210_0-1672361124781.png

 

Sample data used for the charts/table:
Month                                           Scenario         Amount

Saturday, January 1, 20222022 Budget100
Tuesday, February 1, 20222022 Budget100
Tuesday, March 1, 20222022 Budget99
Friday, April 1, 20222022 Budget97
Sunday, May 1, 20222022 Budget97
Wednesday, June 1, 20222022 Budget94
Friday, July 1, 20222022 Budget91
Monday, August 1, 20222022 Budget89
Thursday, September 1, 20222022 Budget89
Saturday, October 1, 20222022 Budget89
Tuesday, November 1, 20222022 Budget89
Thursday, December 1, 20222022 Budget89
Saturday, January 1, 20222022 Actuals100
Tuesday, February 1, 20222022 Actuals103
Tuesday, March 1, 20222022 Actuals105
Friday, April 1, 20222022 Actuals103
Sunday, May 1, 20222022 Actuals103
Wednesday, June 1, 20222022 Actuals104
Friday, July 1, 20222022 Actuals102
Monday, August 1, 20222022 Actuals101
Thursday, September 1, 20222022 Actuals100
Saturday, October 1, 20222022 Actuals101
Tuesday, November 1, 20222022 Actuals102
Thursday, December 1, 20222022 Actuals103
Friday, January 1, 20212021 Actuals100
Monday, February 1, 20212021 Actuals100
Monday, March 1, 20212021 Actuals98
Thursday, April 1, 20212021 Actuals97
Saturday, May 1, 20212021 Actuals94
Tuesday, June 1, 20212021 Actuals91
Thursday, July 1, 20212021 Actuals89
Sunday, August 1, 20212021 Actuals91
Wednesday, September 1, 20212021 Actuals88
Friday, October 1, 20212021 Actuals89
Monday, November 1, 20212021 Actuals87
Wednesday, December 1, 20212021 Actuals89
1 ACCEPTED SOLUTION

Hi,

It looks like the limitation in a line chart is that one cannot drag more than 1 measure to Y-axis.  Therefore, i have used the Line and Clustered column chart.  Can you live this with?

You may download the PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Based on that data that you have shared, please show the expected result in a Table format.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Below is the expected Chart which would have all 3 scenarios on it. 2022 Actuals, 2022 Budget, and 2021 Actuals. I can only seem to get one year of scenarios to show up on the chart at one time.
bjw210_0-1672415857822.png

 

Hi,

It looks like the limitation in a line chart is that one cannot drag more than 1 measure to Y-axis.  Therefore, i have used the Line and Clustered column chart.  Can you live this with?

You may download the PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, this looks nice but unfortunately won't work for my situation. 


Thanks

amitchandak
Super User
Super User

@bjw210 , As you month is in date format, or create a date from month, Join it with date table and then use dateytd

 

example

 

YTD Sales = CALCULATE(SUM(Table[Amount]),DATESYTD('Date'[Date],"12/31"))

 

you can also add a filter

YTD Sales = CALCULATE(SUM(Table[Amount]),DATESYTD('Date'[Date],"12/31"), filter(Table, Table[Scenario] = "Budget") )

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Sorry, had projects come up and just coming back to this one. I ended up doing something similar to what you're talking about but running into a seperate problem. 

Using the DatesYTD seems to only work for the most recent year if multiple years exist where i need to pass filters. When I use the filter funtion, I can pass the right year to the measure but it won't calculate for periods that don't have transactions. 


In the below,

  • I can get DatesYTD to work for both actuals and budget for the most recent year in the table, but doesn't work for prior years (end table will have data back 5+ years so I wouldnt' be able to use SAMEPERIODLASTYEAR). DatesYTD seems to calculate across all months even when no transactions exist
  • I can get Filters to work for all periods and scenarios however, it does not calculate for periods that did not have a transaction. This means a month with no transaction would show 0 for YTD which would be wrong. The Filter Column in the below should show amounts in each month regardless of having a transaction.

bjw210_0-1676149241004.png

DatesYTD =
    CALCULATE(
        SUM(Sheet2[Amount])
        ,DATESYTD(Dates[Date])
    )

Filter =
    Var __Year = LEFT(SELECTEDVALUE(Sheet2[Scenario]),4)
    Var __Month = LOOKUPVALUE(Dates[Month Number],Dates[Month Name],SELECTEDVALUE(Dates[Month Name]))
    Var __Date = DATE(__Year,__Month,1)    
    Var __Result =
        CALCULATE(
            SUM(Sheet2[Amount])
            ,FILTER(ALL(Dates),Dates[Year]=__Year && Dates[Date]<=__Date)
        )
Return __Result


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.