cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Narasimha Regular Visitor
Regular Visitor

DAX Formula for Last 4 weeks data

Hi Team,

Am new to power bi dax, i am trying  to display last 4 weeks data with below dax formula.I have Date table and estalished connection with main table.

 

Last4Weeks = IF(DATEDIFF(ClosedTickets[PResolveDate],TODAY(),WEEK)<5 && WEEKNUM(ClosedTickets[PResolveDate]) <> WEEKNUM(today()),"YES" ,"NO")

 

I got below result with above DAX

Capture.PNG

 

Getting Extra week with above DAX, please correct me

4 REPLIES 4
Phil_Seamark Super Contributor
Super Contributor

Re: DAX Formula for Last 4 weeks data

Hi @Narasimha

 

Have you tried 

 

Last4Weeks = IF(DATEDIFF(ClosedTickets[PResolveDate],TODAY(),WEEK)<4 && WEEKNUM(ClosedTickets[PResolveDate]) <> WEEKNUM(today()),"YES" ,"NO")

If this works it's probably because the current week is week 0 for the DATEDIFF calc.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Narasimha Regular Visitor
Regular Visitor

Re: DAX Formula for Last 4 weeks data

@Phil_Seamark: I tried, getting same result like above

Phil_Seamark Super Contributor
Super Contributor

Re: DAX Formula for Last 4 weeks data

Hi @Narasimha

 

I think there is a mis-match on the weekstarting date, so you may want to use the optional argument on the WEEKNUM function based on your week preference

 

WEEKNUM([date] , 1) = week begins on a Sunday through Saturday (US style)

WEEKNUM([date] , 2) = week begins on a Monday through Sunday (Rest of the universe style).

 

So perhaps try variations on

 

Last4Weeks = IF(IFERROR(DATEDIFF(ClosedTickets[PResolveDate],TODAY(),WEEK),-1)<5 && WEEKNUM(ClosedTickets[PResolveDate],1) <> WEEKNUM(today(),1),"YES" ,"NO")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Lolita New Member
New Member

Re: DAX Formula for Last 4 weeks data

Hi there,

I am new to PBI and am using your solution for the same problem, to say wether "yes" or "no" Calendar_Date from my Dates table belong to the last four weeks from today. I get an error that says "The end of the input was reached. 

last4wks2.PNGsee formula

Helpful resources

Announcements
Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 135 members 1,898 guests
Please welcome our newest community members: