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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
gbernardes
Frequent Visitor

Compare periods until same time last month/year

Hello!

 

I need to compare my sells last month and last year but only until the same time as now.

 

Ex: now is 02may22 10hA.M. -> I need to compare until 02apr22 until 10A.M. / 02may21 until 10A.M.

 

Any idea how can I do this? 

PS: dateadd considers all the day, not until the same time

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@gbernardes , Assuming you need from start of month

 

 

This month =
var _max = now()
var _min = eomonth(datevalue(_max) ,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )

 

 

Last one Month Now =
var _maxDt = date(year(today()),Month(today())-1,day(Today()))
var _max = _maxDt+ timevalue(now())
var _min = eomonth(_maxDt,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )


Last one Year SM Now =
var _maxDt = date(year(today())-1,Month(today()),day(Today()))
var _max = _maxDt+ timevalue(now())
var _min = eomonth(_maxDt,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@gbernardes , Assuming you need from start of month

 

 

This month =
var _max = now()
var _min = eomonth(datevalue(_max) ,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )

 

 

Last one Month Now =
var _maxDt = date(year(today()),Month(today())-1,day(Today()))
var _max = _maxDt+ timevalue(now())
var _min = eomonth(_maxDt,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )


Last one Year SM Now =
var _maxDt = date(year(today())-1,Month(today()),day(Today()))
var _max = _maxDt+ timevalue(now())
var _min = eomonth(_maxDt,-1)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[DateTime] >=_min && 'Table'[DateTime] <= _max) )

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.