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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mikegee78
Frequent Visitor

Comparing daily counts year over year

Hello-

 

I am new to Power BI and I have been tasked to create a dashboard where I am comparing traffic counts by day between last year and this year to show the impact of COVID-19.  I would like to do this in a stacked bar chart, but I cannot get it to work.  The data is an excel dump from an SQL database (I'm working remotely so I can't access the database itself) in the form of monthly files.  I've appended these into both yearly queries and a single query with all the data from both years.  What is the best way to approach this?  Thanks!

 

Mike

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @mikegee78 ,

 

You may create a calendar table first, then create relationship with your fact data table on date field.

 

Calendar=CALENDARAUTO

Then create measure like DAX below.

 

Current year count=SUM(Table[Traffic count])

Last year count= CALCULATE(SUM(Table[Traffic count]),DATEADD(Calendar[Date],-1,Year))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xicai
Community Support
Community Support

Hi @mikegee78 ,

 

You may create a calendar table first, then create relationship with your fact data table on date field.

 

Calendar=CALENDARAUTO

Then create measure like DAX below.

 

Current year count=SUM(Table[Traffic count])

Last year count= CALCULATE(SUM(Table[Traffic count]),DATEADD(Calendar[Date],-1,Year))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

DataZoe
Microsoft Employee
Microsoft Employee

You could create a measure for

 

[Traffic] = sum(Traffic[Traffic Counts])

 

and

 

[Traffic Last Year] = calculate([Traffic],dateadd(Traffic[Date],-1,year))

 

Make sure that [Date] is a date or date/time column (or from a calendar table that's marked as a date table).

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Mariusz
Community Champion
Community Champion

Hi @mikegee78 

 

You can use SAMEPERIODLASTYEAR DAX function please see the link below.
https://docs.microsoft.com/en-us/dax/sameperiodlastyear-function-dax

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn



 

amitchandak
Super User
Super User

@mikegee78 , You can create a year behind the measure

example

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

Or Same weekday last year

Week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))

 

and can compare with your date

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.