Referencing a measure in DAX DATESBTWEEN function

pretlow

New Member
Joined
Feb 9, 2015
Messages
2
In Powerpivot 2013 I am trying to calculate unit sales per day between the last time an item was received and the last time it was sold, but I keep getting tripped up by the DATESBETWEEN fuction.
These measures return the dates of of the last recieve and last sale:
Lastsale:=CALCULATE(LASTDATE(InvDetail[Date]), InvDetail[Type]="Sale")
Lastrecv:=CALCULATE(LASTDATE(InvDetail[Date]), InvDetail[Type]="Receive", all(InvDetail[Date]))

This is what I'm using to get the units sold between the last receive and last sale, but it's not working. I don't get an error, just crazy big numbers.
UnitsSold:=calculate(sum(InvDetail[units]), InvDetail[Type]="Sale", DATESBETWEEN(InvDetail[Date], [Lastrecv], [Lastsale]))

If I hard-code in the dates as below, it works.
UnitsSold:=calculate(sum(InvDetail[units]), InvDetail[Type]="Sale", DATESBETWEEN(InvDetail[Date], date(2015,1,1), date(2015,2,1)))

I also have to get the number of dates in that date range too, but I haven't gone there yet.
Is there some reason why I can't use the measures in the DATESBETWEEN function?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Are you using a calendar table?

You need one for DAX Time intelligence to work.

Once you get one, change your InvDetail[Date} references to the date column in your calendar table.
 
Upvote 0
Yes, I do have a calendar table, but when I change the Lastsale measure to :=CALCULATE(LASTDATE(DateMasterX[DateKey]), InvDetail[Type]="Sale")
for example, I just get the last date in the calendar table regardless of the filters on the InvDetail table. All rows show the last date in the calendar table.
 
Upvote 0
gotta ask... did you identify the date table via Design/MarkAsDateTable ??? Time functions freak if you have not done this...
 
Upvote 0
Using the InvDetail on the LastSale/LastRecv measures seems... reasonable. But you can't do a DATESBETWEEN on that guy. That must come from the dates table. Time intelligence functions don't do "gaps"...
 
Upvote 0

Forum statistics

Threads
1,224,065
Messages
6,176,169
Members
452,710
Latest member
mrmatt36

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top