Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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
Solved! Go to Solution.
Drag date to both Axis and Legend and choose the hierarchy level you want
Thanks, I have just figured it out 30 minutes before you wrote. 😊
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!
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
Note that we use a monthly data, hence the dates are, 01/01/2021, 01/02/2021,...
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
77 | |
73 | |
58 | |
35 | |
31 |
User | Count |
---|---|
99 | |
57 | |
56 | |
46 | |
40 |