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
jignaski18
Helper II
Helper II

Returning Last Date of "Use" with DirectQuery report

I am trying to generate the last date of use when time used > 0, for a list of assets within a direct query. The data is structured as follows:

Structure.JPG

 

I would like to generate different measures to create the following tables:

 

Table 1.JPGTable 2.JPG

 

The primary measure I need to solve for is 'Last date used'. My current measure yields this result:

 

result 1.png

 

Last Date Used = 
VAR FirstVisibleOrder =
    MIN ( 'Pump Gear Usage'[Last Stage ID])
VAR PreviousOrder =
    CALCULATE (
        MAX ( 'Pump Gear Usage'[Last Stage ID]),
        REMOVEFILTERS ( Dates[Date] ),
        'Pump Gear Usage'[Last Stage ID] < FirstVisibleOrder,
        'Pump Gear Usage'[Time In Gear] <>0
    )
VAR FilterPreviousOrder =
    TREATAS (
        {
            PreviousOrder
        },
        'Pump Gear Usage'[Last Stage ID]
    )
VAR Result =
    CALCULATE (
        MAX('Pump Gear Usage'[End time]),
        REMOVEFILTERS ( Dates[Date]),
        FilterPreviousOrder
    )
RETURN
    Result

 

 

 

1 ACCEPTED SOLUTION
jignaski18
Helper II
Helper II

@lbendlin thanks for leading me to the solution. This dax ended up working: 

LDU = 
var d = SELECTEDVALUE('Pump Gear Usage'[Pump_Name])
var d2 = CALCULATE(LASTDATE('Pump Gear Usage'[End time]),'Pump Gear Usage'[Pump_Name]=d,'Pump Gear Usage'[Pump Hours]<>0)
VAR LDU  = CALCULATE(MAX('Pump Gear Usage'[End time]),FILTER('Pump Gear Usage','Pump Gear Usage'[End time]<d2 && 'Pump Gear Usage'[Pump_Name]=d))

RETURN
LDU

View solution in original post

4 REPLIES 4
jignaski18
Helper II
Helper II

@lbendlin thanks for leading me to the solution. This dax ended up working: 

LDU = 
var d = SELECTEDVALUE('Pump Gear Usage'[Pump_Name])
var d2 = CALCULATE(LASTDATE('Pump Gear Usage'[End time]),'Pump Gear Usage'[Pump_Name]=d,'Pump Gear Usage'[Pump Hours]<>0)
VAR LDU  = CALCULATE(MAX('Pump Gear Usage'[End time]),FILTER('Pump Gear Usage','Pump Gear Usage'[End time]<d2 && 'Pump Gear Usage'[Pump_Name]=d))

RETURN
LDU
lbendlin
Super User
Super User

I would define "Last Date Used"  thusly:

LDU =
var d=SELECTEDVALUE(Table1[End time])
return CALCULATE(max(Table1[End time]), Table1[End time]<d)
 
(or use MAXX if you don't like CALCULATE)
Then the Days since last used is the difference from the current date.
 
Now I have a question on "Days idle".  Let's say a pump was used on 3/1 and on 3/3.  The date difference is 2, but shouldn't the "days idle"  be only 1 ?
 
Days idle = DATEDIFF([LDU],min(Table1[End time])-1,DAY)

 

lbendlin
Super User
Super User

Please provide sample data in usable format (not as a picture).

File 

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.