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
Anonymous
Not applicable

Get a messure for the last report of a day

Good morning,

Im trying to get the value of a field, in this case "Total vehicle hours (SPN 246)" , of the last message of a day.

I mean for example as you can see:

In this case you can see that the data contains 5 rows, each row correspond to a message at a specific moment. The first one is for a vehicle with ID 802000232. The message is created with de following date: year 2020, month 3, day 22 and hour 6 and minutos 17 and seconds 45. So each lines is the status of the vehicle at that time. 

What i want is to know the value of the field "Total vehicle hours (SPN 246)"  for the last record of a day and vehicle.

In this case for vehicle 802000232 the last total vehicle hours for day 22 at month 3 will be 650.

The goal with this is to be able to define a messure tha is going to respresent the total vehicles hour per day (and vehicle) to be able to compare de productivity of the different vehicles

 

8.png

Thank you

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can refer to the sample .pbix

test_visual_level_filter.PNG

 

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

View solution in original post

7 REPLIES 7
danextian
Super User
Super User

Hi @Anonymous ,

 

Try this:

 

Create a calculated column for the transaction timestamp. Something like:

Date Time =
DATE ( Data[Year], Data[Day], Data[Day] )
    + TIME ( Data[Hour], Data[Minute], Data[Second] )

 

Create another calculated column to determine whether a timestamp is the max for the day and return the total vehicle hours.

Last Vehicle Hours =
VAR __MAX_TIMESTAMP =
    CALCULATE (
        MAX ( Data[Date Time] ),
        ALLEXCEPT ( Data, Data[Year], Data[Month], Data[Day] )
    )
RETURN
    IF ( Data[Date Time] = __MAX_TIMESTAMP, Data[Vehicle Hours] )

You can use this calculated column in a measure.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could try to create the following measure and apply it to the visual level filter.

Measure =
IF (
    MAX ( 'table'[Total vehicle hours] )
        = CALCULATE (
            MAX ( 'table'[Total vehicle hours] ),
            ALLEXCEPT ( 'table', 'table'[VIN], 'table'[Year], 'table'[Month], 'table'[Day] )
        ),
    1
)

test_last report of a day.PNG

 

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

Anonymous
Not applicable

Thank you for answering!!

I tried the way you said but the messure is returning a '1' instead of the value of the 'Total vehicle hours' field for the last record of the day.

9.png

10.png

Hi @Anonymous ,

 

Please apply it to the visual level filter.

 

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

Anonymous
Not applicable

Thank you for answering!

Im not sure if i understand what you mean by "Please apply it to the visual level filter".

In the visualitation, filters i have choosen the new messure created.

1.jpg

Hi @Anonymous ,

 

You can refer to the sample .pbix

test_visual_level_filter.PNG

 

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

bheepatel
Resolver IV
Resolver IV

Hi @Anonymous 

 

I would try the following:

 

1. In that table, create two new columns and call them FullDate and FullTime. You can use the built-in DAX functions DATE() and TIME() and both those functions will ask for Year,Month,Day & Hours,Minutes,Seconds respectively.

 

2. You can then create the following measure:

 

Last Total Hours =

VAR vDate = MAX(Table[FullDate])
VAR vTime = CALCULATE(MAX(Table[FullTime]), Table[FullDate] = vDate)
VAR vHours = CALCULATE(MAX(Table[Hours]), Table[FullDate] = vDate, Table[FullTime] = vTime)

RETURN vHours
 
Hope that helps!

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.