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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
db042190
Post Prodigy
Post Prodigy

what if i want a new column dax formula to sum only on a specific condition

hi we are just getting started wth pbi and you can see below i've created a new column using dax that is the sum of job cost.  What if i want it to sum only when the job number is the same as the job number on this row?

 

daxfortotalcost.PNG

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@db042190 , All jobnumber seems the same, But you can use earlier to get that

 

Sumx(filter(jobs, Jobs[jobnumber] = earlier( Jobs[jobnumber]) ), Jobs[Quantity])

 

Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

hi @db042190 

try like:
 
jobtotalcost = CALCULATE( SUM( jobcost[cost] ), ALLEXCEPT( jobcost, jobcost[jobnumber], jobcost[itemnumber]))
 
or
 
jobtotalcost=
SUMX(
    FILTER(
        jobcost,     jobcost[jobnumber]=EARLIER(jobcost[jobnumber])&&jobcost[itemnumber]=EARLIER(jobcost[itemnumber])
     ),
    jobcost[cost]
)

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@db042190 , All jobnumber seems the same, But you can use earlier to get that

 

Sumx(filter(jobs, Jobs[jobnumber] = earlier( Jobs[jobnumber]) ), Jobs[Quantity])

 

Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

thx, is this also an option?  What if both job number and item id have to match?

jobtotalcost = CALCULATE( SUM( jobcost[cost] ), ALLEXCEPT( jobcost, jobcost[jobnumber] ) )

 

hi @db042190 

try like:
 
jobtotalcost = CALCULATE( SUM( jobcost[cost] ), ALLEXCEPT( jobcost, jobcost[jobnumber], jobcost[itemnumber]))
 
or
 
jobtotalcost=
SUMX(
    FILTER(
        jobcost,     jobcost[jobnumber]=EARLIER(jobcost[jobnumber])&&jobcost[itemnumber]=EARLIER(jobcost[itemnumber])
     ),
    jobcost[cost]
)

can we mark 2 replies as answers in this forum?  

hi @db042190 

yes

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.