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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AndrewUrban
Frequent Visitor

# of Weeks since Last Ordered Help

Hello!

 

I'm looking for a formula to calculate how many weeks it has been since a store has last ordered product.

 

Below is a simple pivot that I would like to turn into a single column with the above formula. For example, it has been "5" weeks since the below store has last ordered product. 

 

AndrewUrban_0-1656428192134.png

 

Thank you so much in advance for your help!!

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @AndrewUrban 

Thanks for reaching out to us.

>>For example, it has been "5" weeks since the below store has last ordered product. 

You can try this measure.

Measure = 
var _lastDate=MAXX(FILTER('Table','Table'[qty]>0),'Table'[date])
var _maxDate=MAXX('Table',[date])
var _weeks= DATEDIFF(_lastDate,_maxDate,WEEK)
return "Weeks since Last Ordered: "&_weeks

 

vxiaotang_0-1657102137676.png

Best Regards,

Community Support Team _Tang

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

View solution in original post

7 REPLIES 7
v-xiaotang
Community Support
Community Support

Hi @AndrewUrban 

Thanks for reaching out to us.

>>For example, it has been "5" weeks since the below store has last ordered product. 

You can try this measure.

Measure = 
var _lastDate=MAXX(FILTER('Table','Table'[qty]>0),'Table'[date])
var _maxDate=MAXX('Table',[date])
var _weeks= DATEDIFF(_lastDate,_maxDate,WEEK)
return "Weeks since Last Ordered: "&_weeks

 

vxiaotang_0-1657102137676.png

Best Regards,

Community Support Team _Tang

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

You're a genius & a scholar! Thank you! 

ribisht17
Super User
Super User

@AndrewUrban 

 

If you are just looking to convert that matrix then you don't have to do much.

 

ribisht17_0-1656434097980.png

 

Regards,

Ritesh

 

Thanks for the quick response, that doesn't seem to work here, see below. The returned output should be 2 & it's 0 across all stores. Any thoughts? Thanks again!

 

AndrewUrban_0-1656435612070.png

AndrewUrban_1-1656435629710.png

AndrewUrban_2-1656435666588.png

 

 

Oh yes, I used Column here.(Try using it)

Let me know if you want to use measure

I used the column with the formula you listed and it doesn't look like that worked either, i'm thinking there's an extra layer to the formula needed to avoid counting all of the "0" weeks & just counting the most recent. Thanks!

 

AndrewUrban_0-1656510696421.png

 

johnt75
Super User
Super User

You can try

Num weeks since last order =
var lastOrder = MAX( 'Table'[Order date])
return DATEDIFF( lastOrder, TODAY(), WEEK)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors