Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
Solved! Go to Solution.
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:
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.
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:
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.
@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])))
HI amit this looks like a work able solution do you have a pbix
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)
User | Count |
---|---|
141 | |
113 | |
104 | |
78 | |
64 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |