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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Talal141218
Helper III
Helper III

Filter next two years based on Today

Hi Experts, 

I want to filter quantity in the sales orders in the next 2 years. I traid to create a mesure, but it's not work as below : 

CALCULATE([CM_SalesLine_SalesOrderLine_OrderQuantity], Fact_SalesOrderLine[ShippingDateRequested_NK] > TODAY() )
Farthermore, the date, that's i want to filtered  is a column in the tabel and not in the separate table. 
Please let me know if you need more information. 
Thanks a lot in advance 
1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

example data:

ValtteriN_0-1692351951590.png

Here we will show values 1, 2 and 3 since 4 and 5 are outside the 2 year period wanted.

In addition to the original table we will need a calendar table:

ValtteriN_1-1692352191983.png

 



Dax:

Measure 2 =
var _sdate = TODAY()
var _edate = MAXX(CALCULATETABLE(DATEADD('Calendar'[Date],2,YEAR),FILTER('Calendar','Calendar'[Date]=TODAY())),[Date]) return
CALCULATE(SUM('Table (4)'[Value]),ALL('Calendar'),DATESBETWEEN('Calendar'[Date],_sdate,_edate))

End result:
ValtteriN_2-1692352907712.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

example data:

ValtteriN_0-1692351951590.png

Here we will show values 1, 2 and 3 since 4 and 5 are outside the 2 year period wanted.

In addition to the original table we will need a calendar table:

ValtteriN_1-1692352191983.png

 



Dax:

Measure 2 =
var _sdate = TODAY()
var _edate = MAXX(CALCULATETABLE(DATEADD('Calendar'[Date],2,YEAR),FILTER('Calendar','Calendar'[Date]=TODAY())),[Date]) return
CALCULATE(SUM('Table (4)'[Value]),ALL('Calendar'),DATESBETWEEN('Calendar'[Date],_sdate,_edate))

End result:
ValtteriN_2-1692352907712.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




eliasayyy
Memorable Member
Memorable Member

Your measure is on the right track, but you'll want to incorporate a filter for the next two years, and ensure that the measure syntax is correct.

so maybe try 

Next2YearsQty = 
CALCULATE(
    [CM_SalesLine_SalesOrderLine_OrderQuantity],
    FILTER(
        ALL(Fact_SalesOrderLine[ShippingDateRequested_NK]),
        Fact_SalesOrderLine[ShippingDateRequested_NK] > TODAY() &&
        Fact_SalesOrderLine[ShippingDateRequested_NK] <= DATEADD(TODAY(), 2, YEAR)
    )
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.