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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
joeyrbbns
New Member

Days Between Last Date and Today

I have a data set with where items have multiple ship dates, I need to calculate the number of weeks between the last shipped date (most recent date) and today. I have tried datediff, creating custom measures, but I cannot seem to get it. Any help would be appreciated. 

 

joeyrbbns_1-1711423492850.png

 

 

1 ACCEPTED SOLUTION

Looks like "lastDate" is a reserved name.  We just need to change the variable name to something else.  Try this:

Shipped Days Ago = var itemNumber = SELECTEDVALUE('YourTable'[ITEM_NUMBER])
var lastDateVal = CALCULATE(
    MAX('YourTable'[SHIPPED_DATE]),
    ALL('YourTable'),
    'YourTable'[ITEM_NUMBER] = itemNumber
)
RETURN
DATEDIFF(Today(), lastDateVal, DAY)

View solution in original post

4 REPLIES 4
joeyrbbns
New Member

Russ,

 

This is perfect! Thanks!

RossEdwards
Solution Specialist
Solution Specialist

Give this a try.  I didn't know your table's name, so i just called it "YourTable"

Shipped Days Ago = var itemNumber = SELECTEDVALUE('YourTable'[ITEM_NUMBER])
var lastDate = CALCULATE(
    MAX('YourTable'[SHIPPED_DATE]),
    ALL('YourTable'),
    'YourTable'[ITEM_NUMBER] = itemNumber
)
RETURN
DATEDIFF(Today(), lastDate, DAY)

 

Hey Ross,

 

I got this error:

joeyrbbns_0-1711424208236.png

 

Looks like "lastDate" is a reserved name.  We just need to change the variable name to something else.  Try this:

Shipped Days Ago = var itemNumber = SELECTEDVALUE('YourTable'[ITEM_NUMBER])
var lastDateVal = CALCULATE(
    MAX('YourTable'[SHIPPED_DATE]),
    ALL('YourTable'),
    'YourTable'[ITEM_NUMBER] = itemNumber
)
RETURN
DATEDIFF(Today(), lastDateVal, DAY)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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