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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Multi year Line chart. the problem is that the dates data are in one Column!

Hello Everyone,

 

Newbie to PBI here, I'm trying to create a line chart that shows sales and 2 lines of 2 different years. In fact, it's a sale comparison between 2 years (2010/2011) for the same period(Jan1, Jan2....., Jan 12). In other words, I would Like to have a line chart with the following:

 

- X Axis  (Jan1, Jan2....., Jan 12).

- Y Axis (sales).

- 2 lines ( a line for 2010 and a line for 2011).

 

Please let me know if you need any more info that could help solve this issue. 

 

Thanks a lot in advance

 


Example.jpg

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Drag date to both Axis and Legend and choose the hierarchy level you want 

Screenshot 2019-09-21 00.04.17.png

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

Drag date to both Axis and Legend and choose the hierarchy level you want 

Screenshot 2019-09-21 00.04.17.png

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks, I have just figured it out 30 minutes before you wrote. 😊

Anonymous
Not applicable

 

Create a column for year for filtering/slicing

Column Year = YEAR('table'[Date])

Then create a measure for total sales

Total Sales = SUM('table'[sales])

Then create a measure (or several measures if you want to look at multiple years) that adjusts the date range that [Total Sales] is looking at.

Total Sales minus X years = CALCULATE([Total Sales], DATEADD('table'[date], -X, YEAR)

Then if you put a slicer or filter on your page using Column Year, Total Sales will show whatever year you have selected and Total Sales minus X years will be adjusted accordingly.

 

For example, if you select 2011 on your filter/slicer, Total Sales will show all sales for 2011 and Total Sales minus X years will show sales for last year (assuming x = 1)

 

If this works for you, please mark my answer as solved. Let me know if you have more questions. Cheers!

Anonymous
Not applicable

Hi! I think this quite unrelated but I tried using your formula but there is an error with how the data is presented. I am only using a card as a visualization

 

Using the DAX formula, total sum last year is blank if only one year is selected. But when consecutive years are selected, it returns a value.   It also doesn't return a value if two non-consecutive years are selected. 

 

Formula I used

Quantity last Year = CALCULATE([Total Water Consumption],DATEADD('Water Consumption'[DATE],-1,YEAR))
Anonymous
Not applicable

Note that we use a monthly data, hence the dates are, 01/01/2021, 01/02/2021,... 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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