The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello!
I'm trying to calculate an average of another measure. So i have "Mileage_value" column that shows how many kilometres a driver has driven and another column "Fuelconsumption_value" that shows how much fuel has been used.
First i calculated how many kilometres a driver has driven.
Solved! Go to Solution.
Hi @Anonymous ,
It cost my time to simulate your dataset.
The key to this problem is that you have to have a column to identify the start and end points, you can see that I have added a new field below - status.
(Of course, this field can also be directly calculated using DAX, but if you can add this column to the data source, any way to consume memory is not recommended)
Then you can use the following DAX formula.
Consumption(L/100km) Avg =
VAR _S_KM =
CALCULATE (
SUM ( Sheet2[KM] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "START" )
)
VAR _E_KM =
CALCULATE (
SUM ( Sheet2[KM] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "END" )
)
VAR _S_FUEL =
CALCULATE (
SUM ( Sheet2[FUEL] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "START" )
)
VAR _E_FUEL =
CALCULATE (
SUM ( Sheet2[FUEL] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "END" )
)
RETURN
DIVIDE ( _E_FUEL - _S_FUEL, _E_KM - _S_KM ) * 100
The results are shown in the below figure, it works perfectly:
Mark this post as solution if this helps,thanks!
( Davis.Z's blog at LinkedIn)
Hi @Anonymous ,
It cost my time to simulate your dataset.
The key to this problem is that you have to have a column to identify the start and end points, you can see that I have added a new field below - status.
(Of course, this field can also be directly calculated using DAX, but if you can add this column to the data source, any way to consume memory is not recommended)
Then you can use the following DAX formula.
Consumption(L/100km) Avg =
VAR _S_KM =
CALCULATE (
SUM ( Sheet2[KM] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "START" )
)
VAR _E_KM =
CALCULATE (
SUM ( Sheet2[KM] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "END" )
)
VAR _S_FUEL =
CALCULATE (
SUM ( Sheet2[FUEL] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "START" )
)
VAR _E_FUEL =
CALCULATE (
SUM ( Sheet2[FUEL] ),
FILTER ( ALLSELECTED ( 'Sheet2' ), 'Sheet2'[STATUS] = "END" )
)
RETURN
DIVIDE ( _E_FUEL - _S_FUEL, _E_KM - _S_KM ) * 100
The results are shown in the below figure, it works perfectly:
Mark this post as solution if this helps,thanks!
( Davis.Z's blog at LinkedIn)
Thank you so much for your help!
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
12 | |
8 | |
8 |