cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Patron
Post Patron

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
Community Support
Community Support

Hi, @Cloud11 

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
Community Support
Community Support

Hi, @Cloud11 

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

Super User IV
Super User IV

@Cloud11 , 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])))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

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

Continued Contributor
Continued Contributor

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
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors