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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
yamina
Helper I
Helper I

dax problem

Hello 

 

Can you help me to solve this issu please ? 

In the card I want to show the result of the previous year in the same period YTD n-1 51246 

yamina_0-1719838493432.png

And the details show this 

yamina_1-1719838657574.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @yamina ,

First of all I think the SAMEPERIODLASTYEAR function requires the Date data type, which is the reason for the wrong result you reported.

I create a table as you mentioned and make it as a matrix.

vyilongmsft_0-1720148260266.png

vyilongmsft_1-1720148275139.png

Then I create a measure and here is the DAX code you can refer.

YTD n-1 = 
CALCULATE(SUM('Table'[Total]), 'Table'[Year] = 2023)

vyilongmsft_2-1720148367353.png

 

 

 

 

Best Regards

Yilong Zhou

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

3 REPLIES 3
Anonymous
Not applicable

Hi @yamina ,

First of all I think the SAMEPERIODLASTYEAR function requires the Date data type, which is the reason for the wrong result you reported.

I create a table as you mentioned and make it as a matrix.

vyilongmsft_0-1720148260266.png

vyilongmsft_1-1720148275139.png

Then I create a measure and here is the DAX code you can refer.

YTD n-1 = 
CALCULATE(SUM('Table'[Total]), 'Table'[Year] = 2023)

vyilongmsft_2-1720148367353.png

 

 

 

 

Best Regards

Yilong Zhou

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

yamina
Helper I
Helper I

@Greg_Deckler 

 

Thank you for  you quick feedback but I try to use DATEADD also, but it doesnt't work. the same error appears

yamina_0-1719841738073.png

 

yamina_1-1719841785576.png

 

Greg_Deckler
Community Champion
Community Champion

@yamina 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-TIT...

 

And especially this alternative to SAMEPERIODLASTYEAR: To **bleep** With DATEADD - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors