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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MrDarian
Helper II
Helper II

Previous row by DAX

I need a DAX Code for calculating Previous row. points:

1. For the first one amount for each program id, it must be 100% because it has not any data before

2. Ralations: One program ID> many task ID -- One Task ID> many Sub task ID -- One task ID> one amount

3. calculate ratio based on previous row in each program ID

like image below:

Capture.PNG

 

Power BI File Link for download: https://gofile.io/d/oOa25R

 

------

@Anonymous 

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @MrDarian ,

 

I think there are multiple threads opened to this question.

 

Pleae find the solution.

 

RatioMeasure =

var _minsub = CALCULATE(MIN('Table'[Sub ID ]), FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID]) && 'Table'[ID] = MAX('Table'[ID])))
var _maxsubid = CALCULATE(MIN('Table'[Amount]),FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID]) && 'Table'[ID] = MAX('Table'[ID])-1 && 'Table'[Sub ID ] = MAXX(ALL('Table'),'Table'[Sub ID ])))
var _previousamount = CALCULATE(MAX('Table'[Amount]), FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID])&&'Table'[ID] = MAX('Table'[ID]) && 'Table'[Sub ID ] = MAX( 'Table'[Sub ID ]) -1))

RETURN
SWITCH(
TRUE(),
 
MAX('Table'[Sub ID ]) = _minsub && MAX('Table'[ID]) = MINX(ALL('Table'[ID]),'Table'[ID]), DIVIDE(MAX('Table'[Amount]),MAX('Table'[Amount])),
MAX('Table'[Sub ID ]) = _minsub, DIVIDE(MAX('Table'[Amount]),_maxsubid),
DIVIDE(MAX('Table'[Amount]),_previousamount)
)
 
 
Regards,
Harsh Nathani

View solution in original post

1 REPLY 1
harshnathani
Community Champion
Community Champion

Hi @MrDarian ,

 

I think there are multiple threads opened to this question.

 

Pleae find the solution.

 

RatioMeasure =

var _minsub = CALCULATE(MIN('Table'[Sub ID ]), FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID]) && 'Table'[ID] = MAX('Table'[ID])))
var _maxsubid = CALCULATE(MIN('Table'[Amount]),FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID]) && 'Table'[ID] = MAX('Table'[ID])-1 && 'Table'[Sub ID ] = MAXX(ALL('Table'),'Table'[Sub ID ])))
var _previousamount = CALCULATE(MAX('Table'[Amount]), FILTER(ALL('Table'),'Table'[PID]= MAX('Table'[PID])&&'Table'[ID] = MAX('Table'[ID]) && 'Table'[Sub ID ] = MAX( 'Table'[Sub ID ]) -1))

RETURN
SWITCH(
TRUE(),
 
MAX('Table'[Sub ID ]) = _minsub && MAX('Table'[ID]) = MINX(ALL('Table'[ID]),'Table'[ID]), DIVIDE(MAX('Table'[Amount]),MAX('Table'[Amount])),
MAX('Table'[Sub ID ]) = _minsub, DIVIDE(MAX('Table'[Amount]),_maxsubid),
DIVIDE(MAX('Table'[Amount]),_previousamount)
)
 
 
Regards,
Harsh Nathani

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors