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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
bgonen7
Helper I
Helper I

Dax: for each pair of transactions: Net the two plus return zero of the smallest amount

I created a matrix. I am trying to create a variable dax formula to do the following:

1.For Each pair, identify the largest of the two and return the Net of the two amounts. (the red rectangle represents a pair with a common number "2110", then 2210 is another pair BUT then 2310 is not a pair).

2.For the smallest amount,,,retun "zero" or blank

3.If there are no pairs (for example 2310) , then return the existed amount that in the column "Amt doc Curr (AP)"

 

bgonen7_1-1678309125564.png

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @bgonen7 ,

 

Please refer to the sample file.

vcgaomsft_0-1678416486979.png

Highlighting the minimum and maximum values in a Power BI matrix

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

bgonen7
Helper I
Helper I

There are three DAX formulas for this solution and I hope someone can help me make these DAX formulas more effeicient:

Formula1:

To sum each line of each pair:

Measure = CALCULATE(sum('model FactAPVendorOpenItem'[Amt Doc currency (AP)]),
ALL('model FactAPVendorOpenItem'[Vendor2],--to remove all filters
VALUES('model FactAPVendorOpenItem'[Pairs]))
 
Formula2:
Measure 2 =
var min1=CALCULATE([Measure]-([Amt Doc Curr (AP)]))--for the Max line,,get the variance between the max and Min values.
return IF([Amt Doc Curr (AP)]>min1,0,1)--if the record of the pair is the smallest then return Zero
 
Formula3:
 
Net Amount = -(IF([Measure 2]=0,0,CALCULATE([Measure]-([Amt Doc Curr (AP)]))-([Amt Doc Curr (AP)]))) -- if Measure2 equal zero, then return zero, Otherwise get the variance between the two amounts >>$149.2M minus 15.9M  which is $133.2M
 
bgonen7_0-1680113417740.png

 

View solution in original post

2 REPLIES 2
bgonen7
Helper I
Helper I

There are three DAX formulas for this solution and I hope someone can help me make these DAX formulas more effeicient:

Formula1:

To sum each line of each pair:

Measure = CALCULATE(sum('model FactAPVendorOpenItem'[Amt Doc currency (AP)]),
ALL('model FactAPVendorOpenItem'[Vendor2],--to remove all filters
VALUES('model FactAPVendorOpenItem'[Pairs]))
 
Formula2:
Measure 2 =
var min1=CALCULATE([Measure]-([Amt Doc Curr (AP)]))--for the Max line,,get the variance between the max and Min values.
return IF([Amt Doc Curr (AP)]>min1,0,1)--if the record of the pair is the smallest then return Zero
 
Formula3:
 
Net Amount = -(IF([Measure 2]=0,0,CALCULATE([Measure]-([Amt Doc Curr (AP)]))-([Amt Doc Curr (AP)]))) -- if Measure2 equal zero, then return zero, Otherwise get the variance between the two amounts >>$149.2M minus 15.9M  which is $133.2M
 
bgonen7_0-1680113417740.png

 

Anonymous
Not applicable

Hi @bgonen7 ,

 

Please refer to the sample file.

vcgaomsft_0-1678416486979.png

Highlighting the minimum and maximum values in a Power BI matrix

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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