Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
2) Birds mortality logs
I want to add new colum in mortality log table wich gives the current birds count by subtracting previous mortality
Solved! Go to Solution.
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
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
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
27 | |
13 | |
11 | |
9 | |
6 |