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
mcornejo_1
Helper I
Helper I

Blank Year over Year Column

Hello,

 

I am relatively new to Power BI so I'm still fumbling through it.  I've tried to use a technique from another post, however, I continue to have an issue. As far as I can tell I have followed the steps correctly. I should be seeing 2015 results in the RevLastYear column next to 2016 as illustrated here but instead only get the Total 30107315 and that is only because I turned on Total row otherwise I have a blank RevLastYear column. I hope I provided enough information to give you an idea of what I'm up against here. Do you think you can help?

 

Year = YEAR(Shipments[Date])

DateMonth = MONTH(Shipments[Date])

SumRevenue = CALCULATE(SUM(Shipments[Total Revenue]))

RevLastYear = CALCULATE([SumRevenue],DATEADD(DATESYTD(Shipments[Date]),-1,YEAR))

 

YoY.jpg

2 ACCEPTED SOLUTIONS
magsod
Solution Supplier
Solution Supplier

Make sure your column Shipments[Date] is of type date value!

 

If you don't want to work with a separate date table and relate that table to your fact table you can still make it work by doing this instead:

Use Shipments[Date] directly in your visualization instead of using the calculations YEAR(..) and MONTH(...)

Power BI will create a date hierarchy for you automatically. 

Change the meassure for RevLastYear to: CALCULATE([SumRevenue],DATEADD(Shipments[Date].[Date],-1,YEAR))

 

That should give you what you are looking for.

 

Br,

Magnus

 

 

View solution in original post

v-shex-msft
Community Support
Community Support

Hi @mcornejo_1,

 

You can use below formula to get the previous years' total.

 

Pervious Year Total =
var currDate=MAX([Date])
return
SUMX(FILTER(ALL(Shipments),Shipments[Date]>=DATE(YEAR(currDate)-1,1,1)&&Shipments[Date]<=DATE(YEAR(currDate)-1,12,31)&&MONTH([Date])=MONTH(currDate)),[Total Revenue])

 

Pervious Year(Month/Year) =
SUMX(FILTER(ALL(Shipments),Shipments[Date]>=DATE(MAX([Year])-1,1,1)&&Shipments[Date]<=DATE(MAX([Year])-1,12,31)&&[Month]=MAX([Month])),[Total Revenue])

 

Result:

Capture.PNGCapture2.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
mcornejo_1
Helper I
Helper I

Thank you all for your responses. I am able to wrap up my project now. Thiyags I did try to use SAMEPERIODLASTYEAR  but I was unable to get that to work either.

v-shex-msft
Community Support
Community Support

Hi @mcornejo_1,

 

You can use below formula to get the previous years' total.

 

Pervious Year Total =
var currDate=MAX([Date])
return
SUMX(FILTER(ALL(Shipments),Shipments[Date]>=DATE(YEAR(currDate)-1,1,1)&&Shipments[Date]<=DATE(YEAR(currDate)-1,12,31)&&MONTH([Date])=MONTH(currDate)),[Total Revenue])

 

Pervious Year(Month/Year) =
SUMX(FILTER(ALL(Shipments),Shipments[Date]>=DATE(MAX([Year])-1,1,1)&&Shipments[Date]<=DATE(MAX([Year])-1,12,31)&&[Month]=MAX([Month])),[Total Revenue])

 

Result:

Capture.PNGCapture2.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@mcornejo_1

 

Did you use SAMEPERIODLASTYEAR function? 

 

CALCULATE(SUM(Shipments[Total Revenue]),SAMEPERIODLASTYEAR(Shipments[Date ].[Date]))

magsod
Solution Supplier
Solution Supplier

Make sure your column Shipments[Date] is of type date value!

 

If you don't want to work with a separate date table and relate that table to your fact table you can still make it work by doing this instead:

Use Shipments[Date] directly in your visualization instead of using the calculations YEAR(..) and MONTH(...)

Power BI will create a date hierarchy for you automatically. 

Change the meassure for RevLastYear to: CALCULATE([SumRevenue],DATEADD(Shipments[Date].[Date],-1,YEAR))

 

That should give you what you are looking for.

 

Br,

Magnus

 

 

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.