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
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
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.

Top Solution Authors