Forum Discussion

tarolz132q's avatar
tarolz132q
New Member
4 years ago
Solved

Avg Balance DAX

Hi Folks,

I would like to measure the Avg coin balance for each day.

The challenge is to calculate only the newst coin balance for each date by USER_ID. if you notice, AF4FF96..... is shown twice! then when 05/26 is being calculated should be ignore the previous values.

The result I would like to see that for the 05/25/22 - 98

The result I would like to see that for the 05/26/22 - 156

8 Replies

      • lbendlin's avatar
        lbendlin
        Super User

         

        Avg = 
        var d = SELECTEDVALUE('Table'[DATE])
        var a = calculatetable(SUMMARIZE('Table','Table'[USER_ID],"md",max('Table'[DATE])),'Table'[DATE]<=d)
        var b = ADDCOLUMNS(a,"mb",var md=[md] return CALCULATE(sum('Table'[COIN_BALANCE]),'Table'[DATE]=md))
        return  divide(sumx(b,[mb]),countrows(b),0)

         

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi tarolz132q ,

    How to get the 05/26/22 - 156?

    Create a measure.

    Measure = VAR _DAYS= COUNTAX(FILTER(ALL('Table'),'Table'[date]=SELECTEDVALUE('Table'[date])),'Table'[date])
    VAR SUM_=CALCULATE(SUM('Table'[COIN_BALANCE]),FILTER(ALL('Table'),'Table'[date]=SELECTEDVALUE('Table'[date])))
    RETURN
    SUM_/_DAYS

    If I have misunderstood your meaning, please provide more details with your desired output.

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Hi Guys, 

    ill try to be more specific.

    I would like to know what is the Coin balance in each time datapoint on my timeline.

    It mean that for every date I would like to sum the last coin balance for each user_id untill that specific date and then divide by the number of players.

     

    The outcome will be chart like that (disregard the values):

    The table is created in a way that in each date user id can appear only once!

    my table:

    DATEUSER_IDCOIN_BALANCE
    6/1/2022572EDE3F07F53CDD800
    6/1/20227FBF5E6AC11263811
    6/1/2022CB086763FC1E3CC64
    6/1/2022CE471B4692E6B8ED120
    6/1/2022F40C6A78878151B392
    6/2/2022233E855015CD343169
    6/2/202273703E52FAD5609566
    6/2/2022A6499BEE8D6C8A4048
    6/2/2022CB086763FC1E3CC69
    6/2/2022CE471B4692E6B8ED135

     

    The measure results should be like that:

    For day 1 it's easy calculation because I have 5 different users, i just sum up all 1017/5 = 203.4

    For day 2 the calculation should include users that might be online in day 1 as well, but I want to take the last coin balance for each user_id then : 1220/8 = 152.5 (8 Different users included, 3 from day 1 and 5 from day 2)