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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-cgao-msft
Community Support
Community Support

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

 

v-cgao-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.