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
tabkaz
Frequent Visitor

current year till date sales vs previous year for the same period

need to calculate a measure that could show values year-wise, the current year till date (Jan 1 - Nov 6 '20) vs previous year same period (Jan 1 - Nov 6 '19); a single measure that can show value for both years or separate measurefor 2019 & 2020. Also a % variance vs previous year

 

BI.png

tried to use many measures but couldn't get the desired result,

GRPs MTD = VAR MaxMonth = CALCULATE(MAX('Calendar'[MonthNum]), ALL('Calendar'),'Calendar'[CurMonthOffset] = -1)
Return CALCULATE([Total GRP],'Calendar'[MonthNum] <= MaxMonth)
the above measure is calculating the sum for Jan - Oct both years, if cutoff period set to 0 it will calculate values till Nov whole month.
https://drive.google.com/file/d/1akOF13RN9nv0M-KIr7Rz0X55-DgtlTp8/view?usp=sharing 

 

1 ACCEPTED SOLUTION
tabkaz
Frequent Visitor

well, i think i have figured out a solution by using an offset function available on the calendar table, filtering it on the day level;

GRPs MTD = VAR MaxMonth = CALCULATE(MAX('Calendar'[day of year]), ALL('Calendar'),'Calendar'[CurweekOffset] = 0)
Return CALCULATE([Total GRP],'Calendar'[MonthNum] <= MaxMonth),FILTER(ALL('Calendar'),'Calendar'[Year] = -1)
 

View solution in original post

4 REPLIES 4
tabkaz
Frequent Visitor

well, i think i have figured out a solution by using an offset function available on the calendar table, filtering it on the day level;

GRPs MTD = VAR MaxMonth = CALCULATE(MAX('Calendar'[day of year]), ALL('Calendar'),'Calendar'[CurweekOffset] = 0)
Return CALCULATE([Total GRP],'Calendar'[MonthNum] <= MaxMonth),FILTER(ALL('Calendar'),'Calendar'[Year] = -1)
 
amitchandak
Super User
Super User

@tabkaz , Try measures like these examples with a date table

 

YTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

 

Last year

 

LYTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())

Thanks Amit, the measures u have posted in not giving the desired result; YTD LY is not showing any result.

 

bi 2.png

Hi @tabkaz,

I'd like to suggest you use date function to manually define the filter range and calculate, please take a look to follow if it helps:

Time Intelligence "The Hard Way" (TITHW)  

If the above also not work for your scenario, please share some dummy data with the raw table structure and expected results to help us clarify your structure and test to coding formula.

How to Get Your Question Answered Quickly 
BTW, I can't access the share link you posted, can you please fix this?
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.