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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Count of all previous dates

Hi,
I have a records based on date fields and i taken a slicer for the date field 
Suppose if I select date range from  01 Mar 2019 to 31 Dec 2019, I need a count of previous date range i.e.,  01 Mar 2019 to 01 Mar 2000

Here I consider that my database have the records from 01 Mar 2000 to 31 Dec 2019 and data is dynamic

Thanks in advance 


 

1 ACCEPTED SOLUTION

@Anonymous 

You need

Last period =
var _min = minx(ALLSELECTED('Date'),('Date'[Date]))

Return
CALCULATE(SUM(Sales[Sales Amount]),filter(ALL('Date'),'Date'[Date]<=_min))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
Greg_Deckler
Community Champion
Community Champion

Perhaps:

 

Measure =
  VAR __MinDate = MIN('Table'[Date])
RETURN
  COUNTROWS(
    FILTER(
      ALL('Table'),
      [Date] <= __MinDate
    )
  )

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try something like 

Measure = 
VAR __min = MIN( 'Calendar'[Date] )
RETURN 
CALCULATE(
    COUNTROWS( 'Calendar' ),
    ALL( 'Calendar' ),
    'Calendar'[Date] < __min
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn


 

 

amitchandak
Super User
Super User

@Anonymous 

What are the previous date, seems like an overlapping date. If you need year behind data , you can use with date calendar

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

Or you same duration last period

Last period =
var _min = minx(ALLSELECTED('Date'),('Date'[Date]))
var _max = maxx(ALLSELECTED('Date'),('Date'[Date]))
var _diff = DATEDIFF(_min,_max,DAY)+1
var _minx = _min-_diff
var _maxx = _max -_diff
Return
CALCULATE(SUM(Sales[Sales Amount]),filter(ALL('Date'),'Date'[Date]>=_minx && 'Date'[Date<=_maxx))

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak ,

I tried the DAX working super But it is getting a year earlier data but I need all years data 

Example : 01 Jan 2000 to 16 Mar 2020 is a range of records in dataset

and I selected a range between 01 Mar 2020 to 16 Mar 2020 then i need a records before 01 Mar 2020 (i.e., from 01 Jan 2000 to 29 Feb 2020)

Thank you Amit for the great response in a less time 

Waiting for the reply 

 

dax
Community Support
Community Support

Hi @Anonymous , 

You also could refer to my sample for details.

Best Regards,
Zoe Zhi

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

 

 

 

@Anonymous 

You need

Last period =
var _min = minx(ALLSELECTED('Date'),('Date'[Date]))

Return
CALCULATE(SUM(Sales[Sales Amount]),filter(ALL('Date'),'Date'[Date]<=_min))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors