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
Syndicate_Admin
Administrator
Administrator

Show kilometers traveled per day and per vehicle

Hello good afternoon to all I have been trying to solve a problem to show the kilometers traveled per vehicle per day

I have a table where the fuel tickets are recorded which consists of several fields, but the main ones are the following economic, loading date and the odometer of the day of the load

tabla_carga.png

What I need is to obtain the mileage traveled by each vehicle on that day, for example the unit with economic number 592 of the day 02/01/2023 Cargo gasoline and its loading odometer was 175,885 and the day 05/01/2023 was 176,142 so in a new column there should be (km traveled) ----> (odometro_carga of 05/01/2023) - (odometro_carga of 02/01/2023) which would remain for the day 05/01/2303 = 257

1.- Details that the days are not consecutive, it can take several days until the next load,

being as follows:

km_dia.png

How could I do it in Power BI Desktop?

achieve it for a general concetrado generating three measures

1.- initial odometer

ODOMETRO_INICIAL = MIN('reg_combustible vehicles'[odometro_carga])

2.-odometro_final

ODOMETRO_FINAL = .MAX('reg_combustible vehicles'[odometro_carga])

3.- RESULT

RESULT = 'SUMS'[ODOMETRO_FINAL]-'SUMS'[ODOMETRO_INICIAL]
but I do not understand you for the day to day, I add your attention and support, thanks
3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

After paying more attention to the detail being as follows:

route =

where _.max = maxx(filter('reg_combustible vehicles' , [cheap] = EARLIER([cheap]) && [fecha_carga] < EARLIER([fecha_carga]) ), [fecha_carga])

return

if(isblank(_.max), 0, [odometro_carga] - maxx(filter('reg_combustible vehicles' , [cheap] = EARLIER([cheap]) && [fecha_carga] =_.max ), [odometro_carga]) )

amitchandak
Super User
Super User

@Syndicate_Admin , A new column

tarvellled =

var _max = maxx(filter(Table , [economico] = earlier([economico])  && [feach_carga] < earlier([feach_carga]) ), [feach_carga])

return

if(isblank(_max), 0, [odometro_carga] - maxx(filter(Table , [economico] = earlier([economico])  && [feach_carga] =_max ), [odometro_carga])  )

 

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

 

@Syndicate_Admin hello good afternoon, I had some problems with the proposed solution, the syntax "BEFORE" does not appear in power bi desktop

error 1.png

I changed it to "EARLIER" and it shows me the following error in the IF

error 2.png

Any idea that is wrong?

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.