sameperiodlastyear using busines

Forum home » Delegate support and help forum » Microsoft Power BI training and help » SAMEPERIODLASTYEAR using business days

SAMEPERIODLASTYEAR using business days

resolvedResolved · Low Priority · Version 2016

James has attended:
Excel Intermediate course

SAMEPERIODLASTYEAR using business days

I had a quick question regarding the use of the SAMEPERIODLASTYEAR dax function. I have data for business days only, so if I select a date that was a weekend the previous year I don’t get any data, is there an obvious solution for this?

I am also looking to do the same for previous day (using LASTDATE) and previous month (using LASTMONTH) basically using a day add of -1 and -30 to get the data.

RE: SAMEPERIODLASTYEAR using business days

Hi James,

Thank you for the forum question.

Sameperiodlastyear will always show the same date last year, so if you have no data for the date last year nothing will be shown. What would you like Power Bi to show if the date previous year is a Saturday or Sunday?

You have a PreviousDay and a PreviousMonth function which can show you previous day and previous month. If you want to compare previous working day is it a bit complicated. We do not have a working day function in DAX.

See the link below how to filter on working days only

https://community.powerbi.com/t5/Desktop/Filter-by-Previous-Working-Day/td-p/651590

Let me know if it not makes sense.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: SAMEPERIODLASTYEAR using business days

Hi Jens,

Thanks for getting back to me.

In answer to your question, i think i'm simply looking to show the comparison of what the number was 1, 20, and 250 business days ago (1 day, 1 month, 1 year).

Rather than having to create logic around what is/isn't a business day, I wanted to use the Business Dates list we have, and simply offset by 1, 20, 250 to get the corresponding date to compare against. I think there are probably a few ways of doing it.

Thanks,
James

RE: SAMEPERIODLASTYEAR using business days

Hi James, My name is Ron and I am part of the Power Bi team with Jens at STL. Your question was so interesting that Jens and I worked hard to see if we could come up with something more accurate than simply using an Offset of 250. Different years have different amounts of business days in a year, so to use a calculation that retrieves the data from 250 business days ago is not accurate enough. If you are comparing this year's data to last year's data and last year's data is a Sunday then a zero would be returned but it was clear that you did not want that to happen. So we built a solution that gives you a more accurate figure than what you are doing at the moment. The SamePeriodLastYear function only works with sequential date ranges so that one was out the door straight away. You only have business days or working days in your list.
The solution:
1. In Excel you will need to create a dates data table by entering
a heading of Dates2020 and enter the date of 1 January 2020 and you then use the autofill handle (bottom right corner of the cell containing that date) and drag it down until the 31 December 2020.
2. Straight away after you filled down you click the icon at the bottom right of the selection where you will find 'Fill options' and it will have the option 'Fill Series' selected. Choose "Fill Weekdays" instead.
3.In Excel you will need to create a second column in the dates data table with a heading of Dates2019 by entering
the date of 1 January 2019 and you then use the autofill handle (bottom right corner of the cell containing that date) and drag it down until the 31 December 2019.
4.Straight away after you filled down you click the icon at the bottom right of the selection where you will find 'Fill options' and it will have the option 'Fill Series' selected. Choose "Fill Weekdays" instead.

You will now have a table that contains the working days in 2020 and 2019. You will see that the dates are off when there is a weekend in either 2019 or 2020 but it aligns again after the weekends.

5. Open Power Bi Desktop and import the dates data table.
6. Import the data tables containing the figures for 2019 and 2020 you wish to compare against eachother
7. Select Model View in Power Bi Desktop
8. create a relationship between the 2019 table with figures and the dates data table by connecting the 2019 dates field from your table with figures to the dates2019 field in the dates data table
9.create a further relationship between the 2020 table with figures and the dates data table by connecting the 2020 dates field from your table with figures to the dates2020 field in the dates data table

You can now create your visualisations in report view and compare year to year and it will give you the closest business day match in 2019 to your 2020 dates. No DAX needed for this.

I attached 2 files to this forum message. One Excel file gives you an example of the dates data table I discussed and it also has two separate tables, one with 2020 dates and values and one with 2019 dates and values for the same dates a year ago to test with.
The second file is the Power Bi report with the model and a few visuals using the data.

I hope the instructions are clear. At least you will have much more accurate analysis than just going 250 days back.

Try it and if you have any more questions please reply to this forum message.

Kind regards

Ron Oldeboom
Learning and Development Consultant
STL-training







Attached files...

James question.pbix
WorkweekdayConondrum.xlsx

RE: SAMEPERIODLASTYEAR using business days

Hi Ron,

Thanks a lot for your response, very useful and i understand how you've done it.

Thanks,
James

 

Training courses

 

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Power BI tip:

Stay Updated and Engage with the Community

Power BI is continually evolving, with new features and updates being released regularly. Stay informed about the latest enhancements by regularly checking the Power BI blog and community forums. Engaging with the Power BI community provides opportunities to learn from others, share your experiences, and get insights into best practices.

View all Power BI hints and tips


Server loaded in 0.11 secs.