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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How to sum values according to other column's value

hi guys!

 

i have been stuck with a particular case with some data in a database i'm trying to graphicate, the thing is, at my job i need to know how much fuel is every car consuming monthly but based on how many kms/mi has traveled vs how many times did load fuel in the same month, so based on this info, it should look like this, kms of car at the beginning of the month, vs kms of car at the end of the month / fuel consumption during month , thing is a car in order to complete some trips it needs to reload fuel every few days so we'd have a duplicate register in fuel column, so what i need to do is to sum the times the car reloaded fuel to make it a total up to the most recent date, so i can filter by car name, i'll write some table so you can see what i want vs what i have

 

TABLE EXAMPLE OF CURRENT DATA

CAR N°DATEFUELKMS
102/1140 LTS200 KMS
205/1120 LTS80 KMS
307/1135 LTS50 KMS
109/1140 LTS150 KMS
208/1145 LTS250 KMS

 

And this is what i would like to have so i can handle the data more easily

CAR N°DATEFUELKMS
109/1180 LTS350 KMS
205/1120 LTS80 KMS
308/1165 LTS330 KMS

 

any advice on this info is truly helpful, thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1668418740239.png

2.create measure with below dax formula

 

Measure 2 = INT( LEFT(SELECTEDVALUE('Table'[FUEL]),2))
Measure =
VAR cur_car =
    SELECTEDVALUE ( 'Table'[CAR N°] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [CAR N°] = cur_car )
VAR tmp2 =
    ADDCOLUMNS ( tmp, "Car", [CAR N°], "_Fuel", [Measure 2] )
VAR _a =
    SUMX ( tmp2, [_Fuel] ) & " LTS"
RETURN
    _a
Measure 3 = INT( LEFT(SELECTEDVALUE('Table'[KMS]),3))
Measure4 =
VAR cur_car =
    SELECTEDVALUE ( 'Table'[CAR N°] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [CAR N°] = cur_car )
VAR tmp2 =
    ADDCOLUMNS ( tmp, "Car", [CAR N°], "_KMS", [Measure 3] )
VAR _a =
    SUMX ( tmp2, [_KMS] ) & " KMS"
RETURN
    _a

 

3. add a table visual with "Table[CAR N°]" and "Table[Date]" field and measure.

set "Table[Date]" is latest

vbinbinyumsft_1-1668418817817.png

vbinbinyumsft_2-1668418853630.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1668418740239.png

2.create measure with below dax formula

 

Measure 2 = INT( LEFT(SELECTEDVALUE('Table'[FUEL]),2))
Measure =
VAR cur_car =
    SELECTEDVALUE ( 'Table'[CAR N°] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [CAR N°] = cur_car )
VAR tmp2 =
    ADDCOLUMNS ( tmp, "Car", [CAR N°], "_Fuel", [Measure 2] )
VAR _a =
    SUMX ( tmp2, [_Fuel] ) & " LTS"
RETURN
    _a
Measure 3 = INT( LEFT(SELECTEDVALUE('Table'[KMS]),3))
Measure4 =
VAR cur_car =
    SELECTEDVALUE ( 'Table'[CAR N°] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [CAR N°] = cur_car )
VAR tmp2 =
    ADDCOLUMNS ( tmp, "Car", [CAR N°], "_KMS", [Measure 3] )
VAR _a =
    SUMX ( tmp2, [_KMS] ) & " KMS"
RETURN
    _a

 

3. add a table visual with "Table[CAR N°]" and "Table[Date]" field and measure.

set "Table[Date]" is latest

vbinbinyumsft_1-1668418817817.png

vbinbinyumsft_2-1668418853630.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi! thanks for your reply, i'm trying out the formula and tell you the outcome

Smalfly
Responsive Resident
Responsive Resident

Hi @Anonymous ,

 

you can achieve that by using the DAX summarize function with :

  • Car No as your groupby_columnName
  • Max (date)
  • Sum(Fuel)
  • Sum(KMS)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors