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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AHMEDMARHOON
Frequent Visitor

Add current value column by subtracting current row from previous row

Dear PBI Community, thank you in advance for the help

 

I am new to Power BI & DAX 

 

I have tow tables

 

1) flock table with an initial number of birds.

AHMEDMARHOON_0-1650177186807.png

 

2) Birds mortality logs 

 

AHMEDMARHOON_1-1650177215530.png

I want to add new colum in mortality log table wich gives the current birds count by subtracting previous mortality 

 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @AHMEDMARHOON 

If you want to do it using DAX, you can first create a one to many relationship between the two tables based on flock id in both tables (that will make it much faster and easier)

the create New Column >

 

Balance No. of Birds =
VAR CurrentID = Mortality[id]
VAR FlockTable =
    CALCULATETABLE ( Motality, ALLEXCEPT ( Mortalit, Mortalit[flock_id] ) )
VAR PreviousIDsTable =
    FILTER ( FlockTable, Mortality[id] <= CurrentID )
VAR TotalMortality =
    SUMX ( PreviousIDsTable, Mortality[mortality] )
VAR FlockPopulation =
    RELATED ( Flocks[no_of_birds] )
RETURN
    FlockPopulation - TotalMortality

 

 

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @AHMEDMARHOON 

If you want to do it using DAX, you can first create a one to many relationship between the two tables based on flock id in both tables (that will make it much faster and easier)

the create New Column >

 

Balance No. of Birds =
VAR CurrentID = Mortality[id]
VAR FlockTable =
    CALCULATETABLE ( Motality, ALLEXCEPT ( Mortalit, Mortalit[flock_id] ) )
VAR PreviousIDsTable =
    FILTER ( FlockTable, Mortality[id] <= CurrentID )
VAR TotalMortality =
    SUMX ( PreviousIDsTable, Mortality[mortality] )
VAR FlockPopulation =
    RELATED ( Flocks[no_of_birds] )
RETURN
    FlockPopulation - TotalMortality

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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