I've a scenario, I need to calculate average inventory per months where we have formula of average inventory is (beginning inventory + closing inventory)/2. if I select any month, then the beginning inventory should have the inventory amount of selected month and closing inventory should have the inventory amount of the last month. After that we will use the above listed formula for calculation. Can anyone help me to achieve this end result in power bi?
Sep 28, 2020 in Power BI 2,295 views

## 1 answer to this question.

Hi @There,

Is there any index field in your table? If this is a case, you can write a formula to use the index to find out the corresponding begin value and end value, then use them to get the average.

```AVG Measure =
VAR _start =
MINX ( ALLSELECTED ( Table[index] ), [index] )
VAR _end =
MAXX ( ALLSELECTED ( Table[index] ), [index] )
RETURN
DIVIDE (
LOOKUPVALUE ( Table[Amount], Table[index], _start )
+ LOOKUPVALUE ( Table[Amount], Table[index], _end ),
2,
BLANK ()
)```

Otherwise, you need to add an index column first.(power bi data model does not contain a row/column index to find out first or last row value).

Hope this helps!!

If you are interested in learning Power BI, check out Power BI Course Topics now!

• 65,910 points

## To Calculate the Standard Deviation in Power BI

Suppose you've to obtain the Standard Deviation ...READ MORE

## How to combine your data or tables in Power BI?

Power BI includes Query Editor which is ...READ MORE

+1 vote

## Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

## Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

+1 vote

## Connect power bi desktop to dataset and create custom reports

Yes using Power BI REST API to ...READ MORE