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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mbuhary
Helper I
Helper I

Sameperiodlastyear without dates in Fact Table

Hi All,

 

I have a fact table with only Year & month.
I have created a Date Table using these two columns via Calendar function using Min Year & month and Max Year & Month and marked it as a Date Table.

But When I try to create a measure for Previous Period Calculations the results appears without any filters for the whole available data.

Measure:

SalesValue = 
VAR SumValue=SUM(Daily_Sales[SalesValue])
VAR Result= CALCULATE(SumValue,SAMEPERIODLASTYEAR(d_Date[Date]))
Return Result

Any help is appreciated.Model.jpg

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@mbuhary , You can then create date from year and month 

example 

date = date([year], [month],1) // I can suggest more ways 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

 

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@mbuhary , You can then create date from year and month 

example 

date = date([year], [month],1) // I can suggest more ways 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

 

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

Thank you, I was thinking on the same lines, and it solved the Issue.

I removed the additional Table d_Year/Month and now directly created relationship of the fact table with date table. So now all Time Intelligence functions are working.

e.g. for same period last year,

 

 

 

mbuhary
Helper I
Helper I

Thank you for your reply in detail.

 

So do you mean that I will not be able to use any Time Intellignce functions using the Date Table ?

amitchandak
Super User
Super User

@mbuhary , With help of d_yearmonth you can get data of the previous year

 

new column in d_yearmonth 

Month Rank = RANKX(all('d_yearmonth '),'Date'[YrMonth],,ASC,Dense)

 

example measure

This Month = CALCULATE(sum('daily_sales'[Qty]), FILTER(ALL('d_yearmonth '),'d_yearmonth '[Month Rank]=max('d_yearmonth '[Month Rank]))


Last Month = CALCULATE(sum('daily_sales'[Qty]), FILTER(ALL('d_yearmonth '),'d_yearmonth '[Month Rank]=max('d_yearmonth '[Month Rank])-1))

 

Last year Month = CALCULATE(sum('daily_sales'[Qty]), FILTER(ALL('d_yearmonth '),'d_yearmonth '[Month Rank]=max('d_yearmonth '[Month Rank])-12))

 

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('daily_sales'[Qty]),filter(ALL('d_yearmonth '),'Date'[Year]=max('d_yearmonth '[Year])))
Last Year = CALCULATE(sum('daily_sales'[Qty]),filter(ALL('d_yearmonth '),'Date'[Year]=max('d_yearmonth '[Year])-1))

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
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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