Average Speed based on table data POWER BI - powerbi

I have a table in power BI with values like that :
and I need to calculate the diference in time
and show a measure with average speed (time / x) with DAX formula
what I tried :
metric = (sumx(table,[date] - EARLIER([date])) * [x])/COUNTROW([data])
but EARLIRER doesn't work

How to calculate the difference in time
dif = DATEDIFF(MAXX(FILTER(All('Table'), 'Table'[date] < EARLIER('Table'[date])), 'Table'[date]), 'Table'[date], SECOND)
How to calculate a measure for the average speed
average = SUMX('Table', 'Table'[x (m)] * 'Table'[dif]) / SUM('Table'[dif])
Those formulas will help you get the correct output/result.

Related

How to calculate percentage contribution in power bi

How to calculate percentage contribution in power bi
I want to calculate percentage contribution on basis on rows
for eg create new column called "% contribution", in this column calculation will be 3904.49/29309.78 next row 8537.75/29309.78 and so on last column should indicate 100% contribution
You need a simple measure on the form:
% of GT =
VAR _all_selected = CALCULATE ( [Measure], ALLSELECTED () )
RETURN
DIVIDE (
[Measure] ,
_all_selected
)
In the ribbon, navigate to measure tools to set the percentage formatting as required.

Measure using datetime in Power BI

I have a table like in the attached image:
As you can see, I have power consumptions of houses by hour.
What I would like to do is create a measure to calculate the average of power consumption by day and other measure to sum this average of power consumption by days depending on a time interval introduced in a filter.
I know it could be easy by don't know how to start with this.
Thanks for your help!
Regards
Start by adding Calculated columns for Date and Time only:
Date = DATEVALUE(FORMAT('Table'[Datetime], "YYYY-MM-DD"))
Time = TIMEVALUE(FORMAT('Table'[Datetime], "hh:mm"))
With this you create a new Calculated table for consumption per day
Consumption per day =
SUMMARIZE(
'Table',
'Table'[Date],
"Avg. Consumption", AVERAGE('Table'[Consumption])
)
and consumption per day for a given time interval
Consumption per day and time interval =
CALCULATETABLE(
SUMMARIZE(
'Table',
'Table'[Date],
"Avg. Consumption", AVERAGE('Table'[Consumption])
),
'Table'[Time] >= TIMEVALUE("00:00"),
'Table'[Time] <= TIMEVALUE("01:00")
)

DAX - RT Measure calculation based on specific selected date in slicer

i have a problem regarding my calculation. I want to visualize the running total over time (for example 01.07 after hours rounded to the nearest half hour to reduce computing power). I have 90 days of data in my dataset. The Problem i have is that the calculation for the dates long time ago (for example 01.12.2021) are super fast and the calculation for recent dates (05.07.2022) are super slow. I think that the measure calculates the running total for the whole column and then the date filter will be applied, which caused the extreme long calculation time for recent dates. Every day has the same amount of rows. Any idea how i can tell the measure to calculate the running total only for the selected date/date which i picked in my filter?
I used the following measures:
Average Sales =
'Measure Table X'[RT Sales] / 'Measure Table X'[RT Rows]
RT Sales = CALCULATE(
Sum('X'[Sales]),
'X'[Time rounded] <= Max('X'[Time rounded]))
RT Rows = CALCULATE(
COUNTA('X'[Time rounded]),
'X'[Time rounded] <= Max('X'[Time rounded]))```
I'm not sure what you are going to achive, but you can try this, this can work faster.
Average Sales =
CALCULATE(
DIVIDE('Measure Table X'[RT Sales] , 'Measure Table X'[RT Rows])
'X'[Time rounded] <= Max('X'[Time rounded]
)
RT Sales = Sum('X'[Sales])
RT Rows =COUNTA('X'[Time rounded])

Power BI Finding the Average of a Measure

I am attempting to create a measure YTD % Price Change.
In the below extract I would like to get the YTD average ( or total ) for both columns and divide them. ( Sum of CY GRPi / Sum of LY GRPi )
Current Attempt;
DIVIDE(CALCULATE('Measures tbl'[CY Net GRPi], all('Fact PMA'[Calendar Year/Month.Calendar Year/Month Level 01.Key])), CALCULATE('Measures tbl'[LY Net GRPi], all('Fact PMA'[Calendar Year/Month.Calendar Year/Month Level 01.Key])))
CY Net GRPi and LY Net GRPi are themselves a culmination of several different measures.
Any help is greatly appreciated!!

Power bi: Calculate the running total and multiply by each months value

I haven't found anything on this, but maybe someone has an idea.
I want to calculate the running total of an amount, and then get a measure that allows to show it per month. This then should be multiplied by a value for that month. 
The data I have is looking like this:
Now i want to get as result:
So, sum up the amounts and then calculate it with this months value. Is this possible as a measure?
Thanks in advance for any help!
Here is one way to do it:
//amount_total measure calculates total amount
amount_total = SUMX(data, data[amount])
//value_total measure calculates total value
value_total = SUMX(data, data[value])
//amount_rt measure calculates running total multiplied by value
amount_rt =
VAR cur_date = MAX(data[date])
VAR rt = CALCULATE(
[amount_total],
FILTER(
ALL(data),
data[date] <= cur_date
)
)
RETURN rt * [value_total]
Result: