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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
newkingdom
Frequent Visitor

How to Find either the max or min using related

I have 2 tables Payment and Sales.

The Payment table has Payment and Write-Off columns that I want to add to the Sales table.

Now the issue is the amounts could be either positive or negative.

Relationship is Payment(many) ---> Sales (one)

 

So I know I have to use the relatedtable. I added the field to the Sales table using the following:

maxx(RELATEDTABLE(Payment), Payment[Write-Off Amount])

 

But now I am not sure how to change the code so that ifthe Write-Off amount is positive instead of grabbing the max, the code will grab the min and when it is positive it will grab the max? Is this even possible in Power BI?

1 ACCEPTED SOLUTION
smpa01
Community Champion
Community Champion

 

Measure =
VAR _sum = SUM(Payment[Write-Off Amount]))
VAR _maxx = MAXX(RELATEDTABLE(Payment),Payment[Write-Off Amount])
VAR _minx = MINX(RELATEDTABLE(Payment),Payment[Write-Off Amount])
RETURN IF(_sum<0,_minx,_maxx)

 

@newkingdom  can you try the above?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

1 REPLY 1
smpa01
Community Champion
Community Champion

 

Measure =
VAR _sum = SUM(Payment[Write-Off Amount]))
VAR _maxx = MAXX(RELATEDTABLE(Payment),Payment[Write-Off Amount])
VAR _minx = MINX(RELATEDTABLE(Payment),Payment[Write-Off Amount])
RETURN IF(_sum<0,_minx,_maxx)

 

@newkingdom  can you try the above?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.