Forum Discussion
SAMEPERIODLASTYEAR - when using with Power BI Date table , it adds future years
Hi, i have used SAMEPERIODLASTYEAR with no problems, before, but when i use it with the date table created in Power BI, somehow i get the 2020 results replicated in 2021, despite there is no data yet from that period(only data to Juli 2020)
My formula in Danish :
7 Replies
- AnonymousNot applicable
Hi bilingual ,
You cna try restricting you Calendar Date to the maximum date in the Data_akk Table
Min Year = Minimum year in Data_akk Table
Max Year = Maximum Year in Data_akk Table
Date = VAR MinYear = YEAR ( MIN ( Data_Akk[Order Date] ) ) VAR MaxYear = YEAR ( MAX ( Data_Akk[Order Date] ) ) RETURN ADDCOLUMNS ( FILTER ( CALENDARAUTO( ), AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear ) ), "Calendar Year", "CY " & YEAR ( [Date] ), "Month Name", FORMAT ( [Date], "mmmm" ), "Month Number", MONTH ( [Date] ) )Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)- bilingual
Helper V
Thanks a lot, it solved and removed 2021, however despite the data is only till Juli 2020, SAMEPERIODLASTYEAR still gives me the 2019 results for August -December and thereby extends the date period to August-December 2020.
Can i limit the formula somehow so it only gives the results for last year for the active months?
- v-yingjl
Community Support
Hi bilingual ,
How did you create the Calendar date table? Could you please consider sharing some screenshots about this issue for further discussion?
Or you can try to use Calendartauto() to create a date table, create relationship with the fact table and use sameperiodlastyear() function to test.
Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
- bilingual
Helper V
Hej Yingjie, this is my Date Calender(Danish)
Kalender =
VAR MinYear = YEAR ( MIN ( Data[Dato] ) )
VAR MaxYear = YEAR ( MAX ( Data[Dato] ) )
RETURN
ADDCOLUMNS (
FILTER (
CALENDARAUTO( );
AND ( YEAR ( [Date] ) >= MinYear; YEAR ( [Date] ) <= MaxYear )
);
"Dato for heltal"; FORMAT ( [Date]; "YYYYMMDD" );
"År"; YEAR ( [Date] );
"Månedsnummer"; FORMAT ( [Date]; "MM" );
"År/måned tekst"; FORMAT ( [Date]; "YYYY/MM" );
"År/måned"; FORMAT ( [Date]; "YYYY/mmm" );
"Månedsnavn_kort"; FORMAT ( [Date]; "mmm" );
"Månedsnavn_UK"; FORMAT ( [Date]; "mmmm" );
"Ugenr"; WEEKNUM([Date];2);
"Ugedag"; FORMAT ( [Date]; "dddd" );
"Ugedag forkortet"; FORMAT ( [Date]; "ddd" );
"Kvartal"; "Q" & FORMAT ( [Date]; "Q" );
"YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" )
)
- Greg_Deckler
Community Champion
You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000
Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008 - Mariusz
Community Champion
- amitchandak
Super User
bilingual , is Jul 2021 is selected in slicer or filtered on the page or you are showing report by Month-year you will.
Also, make sure Kalendar is marked as Calendar table.
other 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 MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH)))) last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH))) last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH)))) Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month)) Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year)) Next month value = CALCULATE(sum('table'[total hours value]),nextmonth('Date'[Date]))Power BI — MTD Questions — Time Intelligence 3–5
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090ePower BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38aTo get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos.