Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
ermak
Frequent Visitor

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

ermak_0-1601560893245.png

 

 

1 ACCEPTED SOLUTION
stevedep
Memorable Member
Memorable Member

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])

 

 

 

balance.png

Link to file

 

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

 

Kind regards, 

 

Steve. 

View solution in original post

4 REPLIES 4
stevedep
Memorable Member
Memorable Member

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])

 

 

 

balance.png

Link to file

 

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

 

Kind regards, 

 

Steve. 

@stevedep Thank you very much! On test data, your solution works for me. But when I try to apply it to a working project it doesn't work. And I can't figure out what's the matter.

 

Link

ermak
Frequent Visitor

@Greg_Deckler, thanks for the advice. I changed the first post a little.

I tried the FIRSTNONBLANK function but it doesn't work.

sum = SUMX(FIRSTNONBLANK (User_ID[Source],'User_ID'[Source]),SUM(User_Balance[User_Balance]))

 

Greg_Deckler
Community Champion
Community Champion

@ermak A little hard to follow. Maybe you want Lookup Min/Max? https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

Otherwise, not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.