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

Calcualte Sameperiod last year sales using CUSTOM CALENDER

Hello All,

I am trying to calculate sameperiod last year sales values by using CUSTOM CALENDER.

My calender looks like as below 

 

Year   Period       StartDate                   EndDate

2019P0130-12-2018 00:00:0026-01-2019 00:00:00
2019P0227-01-2019 00:00:0023-02-2019 00:00:00
2019P0324-02-2019 00:00:0023-03-2019 00:00:00
2019P0424-03-2019 00:00:0020-04-2019 00:00:00
2019P0521-04-2019 00:00:0018-05-2019 00:00:00
2019P0619-05-2019 00:00:0015-06-2019 00:00:00
2019P0716-06-2019 00:00:0013-07-2019 00:00:00
2019P0814-07-2019 00:00:0010-08-2019 00:00:00
2019P0911-08-2019 00:00:0007-09-2019 00:00:00
2019P1008-09-2019 00:00:0005-10-2019 00:00:00
2019P1106-10-2019 00:00:0002-11-2019 00:00:00
2019P1203-11-2019 00:00:0030-11-2019 00:00:00
2019P1301-12-2019 00:00:0028-12-2019 00:00:00
2020P0129-12-2019 00:00:0025-01-2020 00:00:00
2020P0226-01-2020 00:00:0022-02-2020 00:00:00
2020P0323-02-2020 00:00:0021-03-2020 00:00:00
2020P0422-03-2020 00:00:0018-04-2020 00:00:00
2020P0519-04-2020 00:00:0016-05-2020 00:00:00
2020P0617-05-2020 00:00:0013-06-2020 00:00:00
2020P0714-06-2020 00:00:0011-07-2020 00:00:00
2020P0812-07-2020 00:00:0008-08-2020 00:00:00
2020P0909-08-2020 00:00:0005-09-2020 00:00:00
2020P1006-09-2020 00:00:0003-10-2020 00:00:00
2020P1104-10-2020 00:00:0031-10-2020 00:00:00
2020P1201-11-2020 00:00:0028-11-2020 00:00:00
2020P1329-11-2020 00:00:0026-12-2020 00:00:00

For year, every 4 weeks considered as A PERIOD. with that, one FY may have 13 periods. Now, i have sales data for 2020 till 4th period only as below image.

1.PNG

 

Now i would like to calculate previous year sales values for 4 periods only, so that i can compare with current year sales that is for 4 periods only.

 

like wise for every FY, i need to calcualte the sales values based on the number of periods in current year.

i found a blog with what i need but it is for standard calender year.

https://www.goodly.co.in/calculate-sameperiodlastyear-partial-year/

 

Can any one please guide me.

 

Thanks,

Mohan V.

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

Believe that you need to build a calendar table with the start and end dates and also the periods.

 

Using this post and making some adjustments I have created a full calendar table with the Periods using as base your table. Check all the steps in the query after ==========

 

Now create a relationship between the calendar table and the sales then add the following measure:

PY = 
VAR currentYearMaxPeriod =
    CALCULATE (
        MAX ( 'Calendar'[Period] );
        FILTER ( 'Calendar'; 'Calendar'[Date] = MAX ( Sales[Date] ) )
    )
RETURN
    CALCULATE (
        SUM ( Sales[Sales] );
        FILTER (
            ALLSELECTED ( 'Calendar' );
            'Calendar'[Year]
                = MAX ( 'Calendar'[Year] ) - 1
                && 'Calendar'[Period] >= MIN ( 'Calendar'[Period] )
                && 'Calendar'[Period] <= currentYearMaxPeriod
        )
    )

Check PBIX file attach.

 

In my example I have sales until July but as you can see if you change the filter the dates changes.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly. If not, please kindly elaborate more. thanks!

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
MFelix
Super User
Super User

Hi @Anonymous ,

 

Believe that you need to build a calendar table with the start and end dates and also the periods.

 

Using this post and making some adjustments I have created a full calendar table with the Periods using as base your table. Check all the steps in the query after ==========

 

Now create a relationship between the calendar table and the sales then add the following measure:

PY = 
VAR currentYearMaxPeriod =
    CALCULATE (
        MAX ( 'Calendar'[Period] );
        FILTER ( 'Calendar'; 'Calendar'[Date] = MAX ( Sales[Date] ) )
    )
RETURN
    CALCULATE (
        SUM ( Sales[Sales] );
        FILTER (
            ALLSELECTED ( 'Calendar' );
            'Calendar'[Year]
                = MAX ( 'Calendar'[Year] ) - 1
                && 'Calendar'[Period] >= MIN ( 'Calendar'[Period] )
                && 'Calendar'[Period] <= currentYearMaxPeriod
        )
    )

Check PBIX file attach.

 

In my example I have sales until July but as you can see if you change the filter the dates changes.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.