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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
viferenc
Helper II
Helper II

Sum with specific criteria

Dear Community,

 

I would need your support.

 

Here you can see a snapshot from the table.

 

viferenc_0-1617316580140.png

The refuel of the cars is not always at the same time as the route starts or ends. It could happen the refuel is only after several route.

 

I would need a support how I can sum up the KM between two refuel the in the column "correct KM for liter/km", marked yellow and green, only if I have the summed up KM can I calculate the correct liter/km, marked blue and yellow and this avg. liter/km I would like to show in the related route.

 

This logic should work for all licence number.

 

I hope I was somehow understandable

 

If you have a different/better solution I´m open for it.

 

Thank you for your support.

 

Feri

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@viferenc

here is a workaround for you.

1. create an index column in PQ

2. use dax to create a column

Column = 
VAR lastindex=MAXX(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<EARLIER('Table'[Index])&&NOT(ISBLANK('Table'[Refuel]))),'Table'[Index])
return if(ISBLANK('Table'[Refuel]),blank(),if(ISBLANK(lastindex),sumx(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[Distance KM]),sumx(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<=EARLIER('Table'[Index])&&'Table'[Index]>lastindex),'Table'[Distance KM])))

However, I am still not clear about the logic of last column in ur screenshot.

please see the attachment below





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

Proud to be a Super User!




View solution in original post

@viferenc 

please see the attachment

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ryan_mayu
Super User
Super User

@viferenc

here is a workaround for you.

1. create an index column in PQ

2. use dax to create a column

Column = 
VAR lastindex=MAXX(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<EARLIER('Table'[Index])&&NOT(ISBLANK('Table'[Refuel]))),'Table'[Index])
return if(ISBLANK('Table'[Refuel]),blank(),if(ISBLANK(lastindex),sumx(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[Distance KM]),sumx(FILTER('Table','Table'[licence number]=EARLIER('Table'[licence number])&&'Table'[Index]<=EARLIER('Table'[Index])&&'Table'[Index]>lastindex),'Table'[Distance KM])))

However, I am still not clear about the logic of last column in ur screenshot.

please see the attachment below





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

Proud to be a Super User!




Thank you very much.

 

It works perfec.t

 

With my last column I calculate the avg consumption (avg L/100km).  And this avg consumption, which is calculated in Index 3 (32,03 l/100km) I would like to show for Index 2 and Index 1, because it is related to them also. (in the same or in an extra column)

The same should work also for Index 4, the avg consunsuption (33,53 l/100km) which is calculated for Index 5, should be shown in index 4

 

viferenc_0-1617397686511.png

 

I´m really appriciate for your support, it is a huge support.

 

Thank you 

 

Feri

 

 

 

@viferenc 

please see the attachment

 





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

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors