Forum Discussion

orxanbabashov's avatar
orxanbabashov
Frequent Visitor
10 years ago
Solved

average

Hello everybody   Hope so you are doing well.   I am so new to Power BI  and have some difficulties solving some calculation using DAX funtional language.My question is that i wanna to calculate ...
  • ianbarker's avatar
    ianbarker
    10 years ago

    Hi orxanbabashov

     

    Based on your table, the average debt for the 8 days is 80 and not 16.25.

    It looks like you are trying to calculate the daily difference in debt and then create an average of that.

     

    Do you already have the Daily Debt value in your data set or are you looking to calculate it using DAX?

    If you do, then it is a simple case of creating the same measure I mentioned before but based on the Daily Debt field like:

     

    Average Daily Debt = SUM('TableName'[Daily Debt])/COUNTROWS('TableName')

     

    If you are also looking to create the Daily Debt field then this complicates things a little more.

     

    The way I would do it is by first creating an index column in your data.

    Easiest way to do this is by clicking your Edit Queries button, click on the Add Column tab in the ribbon, and then click Add Index Column.

    Each row will then have a uniqe id.

    Then close and apply this change.

    Then click on New Column and create a column with the following formula:

     

    Daily Debt = IF(Sheet1[Date]=LOOKUPVALUE(Sheet1[Date],Sheet1[Index],Sheet1[Index]-1),0,Sheet1[Debt]-LOOKUPVALUE(Sheet1[Debt],Sheet1[Index],Sheet1[Index]-1))

     

    This formula is basically looking at the value on the previous row in the debt column and working out the difference between the two rows.

     

    Once you have this, you can create your average measure as before.

     

    There may be other ways to do this, but I tested it with your dataset and it worked for me!