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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
krixtsup3r
Helper V
Helper V

Previous computation on Dax

Hi guys, just wanna ask on how can I compute from previous which will be based multiple column. See my expected out below and the computation that I did on Excel

 

312312.PNG

 

Thank you so much!

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@krixtsup3r 
Here is a sample file with the solution https://www.dropbox.com/t/7HLKwsbFecvw2MlK

Existing = 
VAR CurrentDate = Data[Month]
VAR CurrentProgramTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Program] ) )
VAR TableOnAndBefore =
    FILTER ( CurrentProgramTable, Data[Month] <= CurrentDate )
RETURN
    SUMX ( TableOnAndBefore, Data[New] - Data[Removed] )

View solution in original post

9 REPLIES 9
tamerj1
Super User
Super User

@krixtsup3r 
Here is a sample file with the solution https://www.dropbox.com/t/7HLKwsbFecvw2MlK

Existing = 
VAR CurrentDate = Data[Month]
VAR CurrentProgramTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Program] ) )
VAR TableOnAndBefore =
    FILTER ( CurrentProgramTable, Data[Month] <= CurrentDate )
RETURN
    SUMX ( TableOnAndBefore, Data[New] - Data[Removed] )

Thank you! This works, but can you explain to me the formula? Also what if I add more columns within it what should I change? 

tamerj1
Super User
Super User

Hi @krixtsup3r 

Is this table visual or source data? Are New and Removed measures? What is the dax code?

Hi @tamerj1, the columns that doesn't have fill are from tables, while the yellow is I am expecting to be a calculated column

@krixtsup3r 
Let's assume New = N, Removed = R, Existing = E then:

E1 = N1 - R1
E2 = E1 + N2 - R2    >>    E2 = N1 - R1 + N2 - R2    >>    E2 = ( N1 - R1 ) + ( N2 - R2 )
Acoordingly 
E1 = ( N1 - R1 )

E2 = ( N1 - R1 ) + ( N2 - R2 )
E3 = ( N1 - R1 ) + ( N2 - R2 ) + ( N3 - R3 )
E4 = ( N1 - R1 ) + ( N2 - R2 ) + ( N3 - R3 ) + ( N4 - R4 ) 
and so on...

which can be represented as SUMX ( Table(From 1 to n), Nn - Rn)

We need to do that for each program seperately. This is what the CALCULATE modifier "ALLEXCEPT" does. So for each row we calculate a table that contains only the rows that belong to the same project of that particular row. Then we filter this table keeping the rows that are on or before the current date of that row i.e. from the 1(st) to the n(th) row. 
Please let me know if you need any further clarfication.

Cool! Thank you so much for explaining

@krixtsup3r 
Thank you. Can you please provide the same sample data as copy/paste so I can prepare a sample file for you?

Here @tamerj1 

MonthYearProgramNewRemovedExisting
8/1/20192019Project 1312
9/1/20192019Project 1451
10/1/20192019Project 167464
8/1/20192019Project X57552
9/1/20192019Project X11857113
10/1/20192019Project X15158206
8/1/20192019Project XBZ29128
9/1/20192019Project XBZ2645287
10/1/20192019Project XBZ537333
11/1/20192019Project XBZ 6327

 

see this one. too complicated. haha

 

https://1drv.ms/x/s!AqYSh-5UaI9Wg19Aub-s5I10So0a

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors