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

SamePeriodLastYear not working as expected

Hi, im writting to see if any of you can help me with my volumen report.

I am trying to compare the volume of  the year 2020 with the year 2019 with the SamePeriodLastYear measure however the measure is not bringing me the values ​​of 2019 ... the strange thing is that works when i compared the volume of 2019 the measure brings me the values ​​of 2018 ... what may be missing?

 

I think something in the formula may be wrong.. there is just this table

CALCULATE([Volume];SAMEPERIODLASTYEAR('Tabla calendario'[Date]))

 

Sin título.png

1 ACCEPTED SOLUTION

HI @Anonymous 

The problem is that there is a filter in 'Maestro CeCo'[Tipo Material]

3.JPG

and in the relationship that there is a wrong logic in it.

4.JPG

 

you could not use "both" between 'Forecast 2019' and 'Tabla calendario', but the relationship is many to many, so you could just adjust the relationship as below:

Step1:

Add a dim Year table

DIM year = SUMMARIZE('Tabla calendario','Tabla calendario'[año])

Step2:

Use this dim year table as a bridge table to create a relationship between 'Forecast 2019' and 'Tabla calendario' as below:

 

5.JPG

Note: cross filter direction between 'Tabla calendario'  and 'Dim year' is "Both'

Result:

6.JPG

By the way, for the built-in date hierarchy of power bi, you'd better use [año] field instead of year hierarchy year of [date] field.

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

7 REPLIES 7
v-lili6-msft
Community Support
Community Support

hi @Anonymous 

Just add just the formula as below:

New Measure = CALCULATE( CALCULATE([Volume],SAMEPERIODLASTYEAR('Tabla calendario'[Date])),ALL('Tabla calendario'[Date]))

Result:

1.JPG

and here is simple sample pbix file, please try it.

 

Regards,

Lin

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

Hi,

I tried with the solution but i still seeing the same results... maybe it is the volume base or the calendar table?

 

* The mesure toneladas.reales is the volume mesu

 

2.png

Try, like this

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year)))

 

If it does not work. If possible please share a sample pbix file after removing sensitive information.Thanks.

My Recent Blog -

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Anonymous
Not applicable

Hi, you can find the pbi file here:
https://drive.google.com/open?id=1XbHnR9ugvEkkboaI9esnSjioys0BJQeI 

 

Thanks in advance.

 

 

HI @Anonymous 

The problem is that there is a filter in 'Maestro CeCo'[Tipo Material]

3.JPG

and in the relationship that there is a wrong logic in it.

4.JPG

 

you could not use "both" between 'Forecast 2019' and 'Tabla calendario', but the relationship is many to many, so you could just adjust the relationship as below:

Step1:

Add a dim Year table

DIM year = SUMMARIZE('Tabla calendario','Tabla calendario'[año])

Step2:

Use this dim year table as a bridge table to create a relationship between 'Forecast 2019' and 'Tabla calendario' as below:

 

5.JPG

Note: cross filter direction between 'Tabla calendario'  and 'Dim year' is "Both'

Result:

6.JPG

By the way, for the built-in date hierarchy of power bi, you'd better use [año] field instead of year hierarchy year of [date] field.

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

Thanks a lot !

amitchandak
Super User
Super User

Just check, if your visual is restricted dates of 2020 and for the same dates you do not have data 2019.

 

Also check

https://community.powerbi.com/t5/Desktop/SAMEPERIODLASTYEAR-not-working-as-expected/m-p/138016

 

I usually use

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year)))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year))))

 

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.