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
Anonymous
Not applicable

Year over Year sales

Hello everyone,

I’m working with a data set encompassing product line, global location, sales quarter, and total sales. I’m trying to create a year over year sales comparison by quarter. My data set looks as follows:

Product Line

Global Location

Sales Quarter

Total Sales

Notebook

North America

2017Q2

1000

Notebook

North America

2017Q3

500

Notebook

North America

2017Q4

750

Notebook

North America

2018Q1

850

Notebook

North America

2018Q2

900

Notebook

North America

2018Q3

1025

Notebook

North America

2018Q4

1250

 

I created a 2nd table to convert the Sales Quarter column (text format) into a date format based on the start date of the quarter (mm/dd/yyyy), then I created a new column “Quarter-Date” to add this new data to the dataset.

I’m now trying to create a column “Prev Yr Total” to create a column from which I can compare the Total Sales to Last Year’s Sales. I’m using the following formula in PowerBI, however I am not getting any results back:

Prev Yr Total = CALCULATE(SUM([Total Sales]),SAMEPERIODLASTYEAR([Quarter-Date]))

I understand that I will not receive a response in every case as the 2016 sales data is not part of the data set. Any idea why I’m not getting any results for the Prev Yr Total formula?

1 ACCEPTED SOLUTION
Geradav
Responsive Resident
Responsive Resident

Hi @Anonymous 

 

Do you have a date table in your data model? And have you created a relationship between the tables?

Also, there is a new feature in Power BI called "Quick Measure" worth looking at.

Annotation 2019-07-31 183841.jpg

Annotation 2019-07-31 183805.jpg

View solution in original post

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

You could refer to my test below. I have added some data for 2016 so that the result will be much obvious.

You could create a year column with LEFT fucntion like this and change the data type to be whole number.

Year = LEFT('Table'[Sales Quater],4)

Then create a date column with the formula below.

date = DATE('Table'[Year],1,1)

In addtion, you need create a calendar table and create the relationship with the original table.

rela.PNG

And then create the measures below.

current_year =
CALCULATE (
    SUM ( 'Table'[Total Sales] ),
    FILTER ( 'Table', YEAR ( 'Table'[date] ) = YEAR ( MAX ( 'calendar'[Date] ) ) )
)
previous_year =
CALCULATE (
    SUM ( 'Table'[Total Sales] ),
    SAMEPERIODLASTYEAR ( 'calendar'[Date] )
)

Here is the output.

Capture.PNG

For more details, please refer to my attachment.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hello Cherry, 

 

Thank you for your help with this endevor. In your example, I see that you are performing the Year over Year comparison task I'm looking for, however it appears that you are comparing Total Year over Year. I may not have communicated this correctly, but I am looking to for a Year over Year comparison by quarter, for example 2017Q2 vs 2018Q2 Totals comparison. 

 

Your assistance is appreciated,

 

Neel D

Geradav
Responsive Resident
Responsive Resident

Hi @Anonymous 

 

Do you have a date table in your data model? And have you created a relationship between the tables?

Also, there is a new feature in Power BI called "Quick Measure" worth looking at.

Annotation 2019-07-31 183841.jpg

Annotation 2019-07-31 183805.jpg

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.