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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jonasgudm
Frequent Visitor

Compare sales from a similar period

Hello,
I work at an airline and I'm trying to compare todays sales with comparison years sales. My problem is with filtering and also the fact that I'm working with different years. Let me illustrate I have a couple of tables. First one is the shifted date table since it is very import to compare day on day sales. So you compare 18 sep 2021 with 19 sep 2022 since both were a monday:

CompyearSalesDateDATESHIFT
20186.9.20224.9.2018
20187.9.20225.9.2018
20188.9.20226.9.2018
20196.9.20223.9.2019
20197.9.20224.9.2019
20198.9.20225.9.2019

Then you have the departure date table. Compyear, DepartureDate and CompyearSame are static, but the rest are measures:

CompyearDepartureDateCOMPYEARSAMEDATEMinYearYearsToAddSameDate
201830.12.202230.12.20182022030.12.2018
201831.12.202231.12.20182022031.12.2018
20181.1.20231.1.2018202211.1.2019
20182.1.20232.1.2018202212.1.2019
201930.12.202230.12.20192022030.12.2019
201931.12.202231.12.20192022031.12.2019
20191.1.20231.1.2019202211.1.2020
20192.1.20232.1.2019202212.1.2020

For this table we do not have to shift the dates but we have to make a measure to see whether we have to add another year to the measure "SameDate" or not based on whether we are filtering on a one or two years. MinYear=YEAR(Min(departureDate)) and YearsToAdd = Year(departureDate) -MinYear.
SameDate = DATEADD(CompYearSameDate,YearsToAdd,Year) 

And then finally we have the Sales figures for the year of 2018 and 2019 (numbers scrambled and filtered based on the criteria I have mentioned above):

Date of saleDeparture dateSold Amount
4.9.201830.12.201850
4.9.201831.12.201860
4.9.20181.1.201970
4.9.20182.1.201980
5.9.201830.12.201855
5.9.201831.12.201866
5.9.20181.1.201977
5.9.20182.1.201988
6.9.201830.12.201861
6.9.201831.12.201873
6.9.20181.1.201985
6.9.20182.1.201997
3.9.201930.12.201967
3.9.201931.12.201980
3.9.20191.1.202093
3.9.20192.1.2020106
4.9.201930.12.201973
4.9.201931.12.201988
4.9.20191.1.2020102
4.9.20192.1.2020117
5.9.201930.12.201981
5.9.201931.12.201997
5.9.20191.1.2020113
5.9.20192.1.2020129

 

Now I just need a measure which sums up both for each "compyear". So in this example 2018 = 861, 2019 = 1145.
If you have a better solution to my thinking I would love that, DAX is not my strongest side but that is how I think it would be done nicest

1 REPLY 1
daXtreme
Solution Sage
Solution Sage

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.