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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Nepal101
Helper III
Helper III

DAX Query for last 24 month using dax studio

Hello Everyone, 
Need some help with the DAX query. I copied the DAX from the performance analyzer but need to add a dynamic filter formula can anyone take a look and provide any suggestions? instead of the dates, I need the last 24 months of date listed under VAR __DS0FilterTable2 

I tried this 
    VAR __DS0FilterTable2 = 
        FILTER(
            KEEPFILTERS(VALUES('dimDate'[FullDate])),
            AND('dimDate'[FullDate] >= DATEADD('dimDate'[FullDate],-24,Month), 'dimDate'[FullDate] < DATEADD('dimDate'[FullDate],0,Month))
it is giving blank value

// DAX Query
DEFINE
    VAR __DS0FilterTable = 
        TREATAS({"Y"}, 'dimDOTCarry'[IsActive])

    VAR __DS0FilterTable2 = 
        FILTER(
            KEEPFILTERS(VALUES('dimDate'[FullDate])),
            AND('dimDate'[FullDate] >= DATE(2021, 7, 21), 'dimDate'[FullDate] < DATE(2023, 7, 21))
        )

    VAR __DS0FilterTable3 = 
        TREATAS({4}, 'dimDOTCarrierInfo'[FMSID])

    VAR __DS0Core = 
        SUMMARIZECOLUMNS(
            'dimCrash'[Crash Date],
            'dimCrash'[Report Number],
            'dimDOTCarry'[Number],
            'dimDOTCarry'[Name],

Thank you so much for the time. 

2 REPLIES 2
Nepal101
Helper III
Helper III

Thank you for your reply, 
I was wondering if it is possible to just calculate the filter for the date rather than using it for any fact field like calculate ( sum(Table[Value]). 
Please let me know if there is any way to do it 

amitchandak
Super User
Super User

@Nepal101 , Last 24 month based on today 

 

24 month Today =
var _min = date(year(today()), month(today())-24,day(today()) )
var _max = today()
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

All About Time Intelligence around Today: https://youtu.be/gcLhhxhXKEI

 

If you want select date and want aggregated 24 months values

 

Rolling 12 Sales =
var _max = maxx(allselected(date),date[date]) // or today()
var _min = date(year(_max), month(_max)-12,1)
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date), date[date] <=_max && date[date] >=_min))

 

If you need trend then you need slicer on independent table

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = date(year(_max), month(_max)-24, Day(_max))
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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