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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Calculate previous year sales based on mini and max date

Hi Experts

 

For the year 2019 my dates run from 29.12.2018 to 30.12.2019  I want to dynamically calculate the sales based on year slicer. The year 2018 runs from 28.12.2018 to 28.12.2019..

 

Don't as why?

 

My sales table is Fact Edw Sales

My DimDate is Edw Time with a date column and year and periods column

 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I create some data, and you can try this measure:

Year sales =
var _selectedyear=YEAR(MIN('DimDate'[Date]))
return
SWITCH(
    _selectedyear,
    2018,CALCULATE(SUM('Fact Edw Sales'[Sales]),FILTER('Fact Edw Sales',[Date]>=DATE(2018,12,28)&&[Date]<=DATE(2019,12,28))),
    2019,CALCULATE(SUM('Fact Edw Sales'[Sales]),FILTER('Fact Edw Sales',[Date]>=DATE(2018,12,29)&&[Date]<=DATE(2019,12,30))),
    BLANK())

 

Then you can create a Slicer (place ‘DimDate’ [year] ) and a card chart(place this measure [Year sales]), like this:

v-robertq-msft_0-1605668464636.png

 

And you can get what you want.

You can download my test pbix file here

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

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

4 REPLIES 4
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I create some data, and you can try this measure:

Year sales =
var _selectedyear=YEAR(MIN('DimDate'[Date]))
return
SWITCH(
    _selectedyear,
    2018,CALCULATE(SUM('Fact Edw Sales'[Sales]),FILTER('Fact Edw Sales',[Date]>=DATE(2018,12,28)&&[Date]<=DATE(2019,12,28))),
    2019,CALCULATE(SUM('Fact Edw Sales'[Sales]),FILTER('Fact Edw Sales',[Date]>=DATE(2018,12,29)&&[Date]<=DATE(2019,12,30))),
    BLANK())

 

Then you can create a Slicer (place ‘DimDate’ [year] ) and a card chart(place this measure [Year sales]), like this:

v-robertq-msft_0-1605668464636.png

 

And you can get what you want.

You can download my test pbix file here

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , I am assuming you have year(FY) or year start date, now bases on year or year start date you can get these calculation

Add columns in date table 

Start of year = based on calendar 

Year Rank = RANKX(all('Date'),'Date'[Year Start date],,ASC,Dense)

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
rolling = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]>=max('Date'[Year])-2 && 'Date'[Year]<=max('Date'[Year])) )

diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])


This Year = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])))
Last Year = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1))

 

YTD= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))
LYTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1 && 'Date'[Day of Year] <= Max('Date'[Day of Year])))

Anonymous
Not applicable

HI amit this looks like a work able solution do you have a pbix

speedramps
Super User
Super User

Please consider this solution and leave kudos ....

 

Use a Calendar table with a [dontaskwhyyearoffset] column which runs  from 28/12 to 27/12,

eg yearoffset  = 0 is this year, -1 is last year, -2 is the previous year and +1 is next year

 

Then use the offset in filters and CALCULATE measures

eg sales last year = CALCULATE(SUM(Sales[value]),Calendar[dontaskwhyyearoffset] = -1)

 

Watch this video 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.