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
rdorsey
Frequent Visitor

How do I get two YTD lines on a single year plot?

I'm trying to compare incoming items from this year and last year. The visual I've been asked to provide is a line and clustered column chart where the X axis is "Month" and the Y is "Items". The columns need to be the total items for each month and the lines should be a YTD sum of the items. I have successfully done all of this except for getting both of the lines to show up on a single 12 month scale, I can only get the current year's YTD data to show up on the plot. I think my issue has something to do with how the Date hierarchy is interacting with things, but I can't figure out much past that.

If it helps, here's the DAX for the measures I'm using:

Last Year: 

CALCULATE(COUNTA('Shipped'[Id]), YEAR('Shipped'[Date]) = YEAR(TODAY())-1)
This Year:
CALCULATE(COUNTA('Shipped'[Id]), YEAR('Shipped'[Date]) = YEAR(TODAY()))
YTD Last Year:
CALCULATE(TOTALYTD(COUNTA('Shipped'[Id]), 'Shipped'[Date].[Date]),YEAR('Shipped'[Date]) = YEAR(TODAY())-1)
YTD This Year:
CALCULATE(TOTALYTD(COUNTA('Shipped'[Id]), 'Shipped'[Date].[Date]),YEAR('Shipped'[Date]) = YEAR(TODAY()))
 
Ive also attached a picture of some visuals and table illustrating the issue:
 
Basically I just need the visual on the left to also have the orange line from the visual on the right.Basically I just need the visual on the left to also have the orange line from the visual on the right.
 
Any help would be greatly appreciated!
1 ACCEPTED SOLUTION
aj1973
Community Champion
Community Champion

Hi @rdorsey 

To use Time Intelligence Functions you need to add a Calendar table to your model and relate it to the "Shipped" table @ the DATE column. Then you will use DATEADD to get YTD_LastYear. like here

YTD__LastYear = CALCULATE([Sales] , DATEADD('Calendar'[Date] , -1, MONTH))
YTD__ = CALCULATE([Sales] , DATEADD('Calendar'[Date], 0 , MONTH))
aj1973_1-1630700144859.png

 


 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

View solution in original post

1 REPLY 1
aj1973
Community Champion
Community Champion

Hi @rdorsey 

To use Time Intelligence Functions you need to add a Calendar table to your model and relate it to the "Shipped" table @ the DATE column. Then you will use DATEADD to get YTD_LastYear. like here

YTD__LastYear = CALCULATE([Sales] , DATEADD('Calendar'[Date] , -1, MONTH))
YTD__ = CALCULATE([Sales] , DATEADD('Calendar'[Date], 0 , MONTH))
aj1973_1-1630700144859.png

 


 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

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.