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

View all the Fabric Data Days sessions on demand. View schedule

Reply
mpcbto1
New Member

Time comparison and line charts

Hello,

I've read many posts in this forum but did not find one answering my question.

 

I have a data model with a DimDate table (days from 01.2018 to today) and another table with Traffic (Google Analytics users) data, on a day basis. Both tables are connected in the data model (via the date dimension).

I have a slicer to allow report users to filter on dates.

 

I created a measure to calculate the traffic of the previous period. I don't use timeintelligence functions because I want the users to be able to select a custom date range (e.g 04/30 to 06/08 as shown above).

Var_Users =

VAR date_range = COUNTA(DimDate[Date])
VAR sum_prevperiod = IF(
date_range=0,0,
CALCULATE(SUM('Raw_Data'[Users]),dateadd(DimDate[Date],-date_range+1,DAY))
)

return sum_prevperiod 

This works perfectly fine for "card" or "KPI" visuals for instance: the data displayed is the one from the previous period.

But I'd like to have a line chart comparing the data between the selected period and the previous period.

The issue is: The visual merges both lines into one, showing the same data.

 

Annotation 2020-06-11 102554.png

 

Do you guys have any idea on how I can overcome this?

Thanks!

2 REPLIES 2
amitchandak
Super User
Super User

@mpcbto1 , The information you have provided is not making the problem clear to me. Can you please explain with an example.
Check if this blog can help

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601
Appreciate your Kudos.


Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak

Thanks for the reply.

I would like to be able to compare the Traffic data between two time periods: the current time period (selected in the slicer shown in my initial post) and the previous time period.

For instance : comparing Traffic data of 04/30/2020-06/08/2020 to 04/29/2020-03/21/2020.

 

To do this, I have created the measure shown in the initial posts, using DATEADD. This measure works very well when I use "KPI" or "cards" visuals, to show total data (Current period total traffic and Previous period total traffic).

 

However, I would like to show the variation of Traffic day over day in a Line Chart, and compare it to the previous period.

I would then get a line chart with:

- X axis: days (04/30/2020-06/08/2020 in my example)

- Y axis: Traffic

- 2 lines: traffic of current period (red value in the screenshot) and traffic of previous period (light red value in the screenshot).

- 2 doted trendlines for the current period and previous period

 

But that does not work, as shown in the screenshot, PowerBi merges both lines into one: apparently the measure I've created does not work for this kind of visualization.

 

I hope this makes more sense to you!

Thanks again

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors