Forum Discussion

ermak's avatar
ermak
Frequent Visitor
6 years ago
Solved

SUM value from only the first occurrence

I have two tables ('UserID' and 'User_Balance'). In one - the source of traffic and user ids, in others, user ids and their balances. I create a connection and display into a table just the sums of user balances. But, one user can go from several traffic sources and his balance will be indicated everywhere. As a result, the total amount is considered incorrect. Can I create a measure that calculates the balance amount for the first occurrence only? Thanks!

My test 

 

UserID

SourceUserIDDate
google / cpc11101.01.2020
google / organic22201.01.2020
google / organic11102.01.2020
yahoo / organic33303.01.2020
(direct) / (none)22203.01.2020

 

User_Balance

UserIDUser_Balance
111123
222444
333323

 

Expected Result

SourceUser_Balance
(direct) / (none) 
google / cpc123
google / organic444
yahoo / organic323

 

Current result

 

 

  • Hi ermak ,

     

    See below:

     

     

     

    __New = 
    SUMX(SUMMARIZE(ALL_HITS,ALL_HITS[user_id], "b",
    IF(
     CALCULATE(FIRSTNONBLANK(ALL_HITS[date],MIN(ALL_HITS[hits_referer])), ALLEXCEPT(ALL_HITS, ALL_HITS[user_id])) = MIN(ALL_HITS[date]) , MIN('Users Balance'[Balance USD]), BLANK())
    ),[b])

     

     

     

    Link to file. 

     

    Please mark as solution if so. Thumbs up for the effort are appreciated.

     

    Kind regards, 

     

    Steve. 

4 Replies