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

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

Reply
cpmb
Frequent Visitor

Conditional reference to another row in table

Could somebody explain why I am getting the numbers below in the Output column? I had expected to get those in the Desired Output column instead. DAX Formulas are below.

DateGroupIDValueOutputDesired Output
1/1/2019A1555
1/1/2019A2101010
1/1/2019A3151515
1/1/2019B4202020
1/1/2019B5252525
1/2/2019A1-102030
1/2/2019A2303030
1/2/2019B4353535
1/2/2019B5-103535
1/2/2019A3-102030

 

Output = IF(

Table[Value]<0,

CALCULATE([Measure],

FILTER(

SUMMARIZE(Table, Table[Date],Table[Group],Table[ID],Table[Value]),

Table[Date]=EARLIER(Table[Date]) && Table[Group] = EARLIER(Table[Group]) && Table[ID] <> EARLIER(Table[ID])

)), Table[Value])

 

Measure= CALCULATE(

SUM( Table[Value]),

ALLSELECTED(Table[ID]),

FILTER(Table, Table[Date]=Table[Date] && Table[Group]=Table[Group] && Table[ID] = Table[ID]))

 

Any explanation would be great, Thanks.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

 

NewCol =
IF (
    Table1[Value] < 0,
    CALCULATE ( MAX ( Table1[Value] ), ALL ( Table1[ID], Table1[Value] ) ),
    Table1[Value]
)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

View solution in original post

5 REPLIES 5
AlB
Community Champion
Community Champion

Hi @cpmb 

Can you explain how the correct numbers are calculated, what the logic is?

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

 

cpmb
Frequent Visitor

The logic is: if Value is negative, take the Value of another ID in the Group (ideally the max).

AlB
Community Champion
Community Champion

 

NewCol =
IF (
    Table1[Value] < 0,
    CALCULATE ( MAX ( Table1[Value] ), ALL ( Table1[ID], Table1[Value] ) ),
    Table1[Value]
)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

cpmb
Frequent Visitor

Thank you @AlB . Works perfectly. Could you give me an explanation as to why the Group doesn't need to be referenced in the NewCol formula?

AlB
Community Champion
Community Champion

Sure, cause we want to look at the max by Date and Group, right? Context transition establishes filters on those only since with the ALL( ) we are eliminating the filters on ID and Value.

If you're not familiar with context transition check this out:

https://www.sqlbi.com/articles/understanding-context-transition/    

 

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.