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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Cday21
Frequent Visitor

Power Pivot - Calculated Column - How to find the 2nd minimum value based on other column groups

I'm having trouble creating a Calculate Column in Power Pivot.

I have a table that shows bid results from multiple suppliers for multiple items and divisions.  

 

Through research I've been able to figure out the DAX formula for the minimum bid (by Division, by Item). 

=CALCULATE(MIN(Table1[Bid Cost]),ALLEXCEPT(Table1,Table1[WAREHOUSE / DIVISION],Table1[ITEM NAME]))

I was also able to figure out the percent difference based on the lowest bid.  

=(Table1[Bid Cost]-CALCULATE(MIN(Table1[Bid Cost]),ALLEXCEPT(Table1,Table1[WAREHOUSE / DIVISION],Table1[ITEM NAME])))/Table1[Bid Cost]

 

I'm now being asked if I can do the same for the 2nd lowest bid (by Division, by Item) to place in a Pivot Table for when we make negotiation calls. 

 

I've been looking for a couple days through the forum and google, and cannot seem to find an answer for the 2nd lowest value Calculated Column.

In Excel, the formula would be:

2nd Lowest Bid =SMALL($D$5:$D$13,2)
% From 2nd Lowest Bid =(D5-SMALL($D$5:$D$13,2))/D5

 

Here is my data sample.  I apologize, I'm trying to figure out how to attached the sample data file, but my OneDrive and GooglDrive is blocked by IT security.

 

Cday21_1-1674070509488.png

 

 

 

5 REPLIES 5
DataInsights
Super User
Super User

@Cday21,

 

This calculated column leverages the existing calculated column Lowest Bid:

 

2nd Lowest Bid = 
CALCULATE (
    MIN ( Table1[Bid Cost] ),
    ALLEXCEPT ( Table1, Table1[WAREHOUSE / DIVISION], Table1[ITEM NAME] ),
    Table1[Bid Cost] > Table1[Lowest Bid]
)

 

The logic can be adapted for the % difference measure. Another option is RANKX if you need the 3rd smallest, 4th smallest, etc.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello, I know this is an old question, but needed to revert back to it. I tried your suggestion. However, I am getting multiple errors:
The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression.
A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

@Cday21,

 

Would you be able to provide your DAX, and note whether it is a measure or calculated column? If you can paste your sample data as a table, that would help.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@DataInsights 

This is a Calculated Column.  The ultimate goal is to have this data in a Pivot Table (w. Slicers), and be able to see the % difference between the 1st & 2nd lowest bid (By Warehouse, By Time).

 

I have the Calculated Column for the 1st lowest bid:

 

=CALCULATE(MIN('Table1'[BID COST]),ALLEXCEPT(Table1,Table1[WAREHOUSE],Table1[ITEM NAME]))

 

and the % difference.

 

=('Table1'[BID COST]-CALCULATE(MIN('Table1'[BID COST]),ALLEXCEPT(Table1,Table1[WAREHOUSE],Table1[ITEM NAME])))/'Table1'[BID COST]

 

 

I still need the 2nd Lowest bid. I tried to use your code to find the 2nd lowest bid, but it's throwing an error:

 

=CALCULATE(MIN('Table1'[BID COST]),ALLEXCEPT(Table1,Table1[WAREHOUSE],Table1[ITEM NAME]),'Table1'[BID COST]>'Table1'[Lowest Bid])

 

The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression.

 

?Would this be easier to do in Power Query before I add the Data to the Date Model?

 

Sample Table:

SUPPLIERWAREHOUSEUPCITEM NAMEBID COSTPROJECTED VOLUMESUPPLIER'S VOLUMELOWEST BID% From Lowest Bid2nd Lowest Bid% From 2nd Lowest Bid
Supplier BWarehouse F1111111111Item A$3.94141,597141,597$3.940.0%$5.65-43.4%
Supplier HWarehouse F1111111111Item A$5.65141,597141,597$3.9430.3%$5.650.0%
Supplier DWarehouse F1111111111Item A$5.70141,597141,597$3.9430.9%$5.650.9%
Supplier AWarehouse F1111111111Item A$5.81141,597141,597$3.9432.2%$5.652.8%
Supplier GWarehouse F1111111111Item A$5.86141,597141,597$3.9432.8%$5.653.6%
Supplier FWarehouse F1111111111Item A$6.05141,597141,000$3.9434.9%$5.656.6%
Supplier EWarehouse F1111111111Item A$6.50141,597141,597$3.9439.4%$5.6513.1%
Supplier CWarehouse F1111111111Item A$7.27141,597135,000$3.9445.8%$5.6522.3%
Supplier AWarehouse F2222222222Item B$6.3580,60480,604$6.163.0%$6.212.2%
Supplier BWarehouse F2222222222Item B$6.4780,60480,604$6.164.8%$6.214.0%
Supplier CWarehouse F2222222222Item B$6.5680,60475,000$6.166.1%$6.215.3%
Supplier DWarehouse F2222222222Item B$6.2180,60480,604$6.160.8%$6.210.0%
Supplier EWarehouse F2222222222Item B$6.6180,60480,604$6.166.8%$6.216.1%
Supplier FWarehouse F2222222222Item B$6.6680,60480,000$6.167.5%$6.216.8%
Supplier GWarehouse F2222222222Item B$6.4280,60480,604$6.164.0%$6.213.3%
Supplier HWarehouse F2222222222Item B$6.1680,60480,604$6.160.0%$6.21-0.8%
Supplier AWarehouse K1111111111Item A$5.5683,46983,469$3.8231.3%$5.560.0%
Supplier BWarehouse K1111111111Item A$3.8283,46983,469$3.820.0%$5.56-45.5%
Supplier CWarehouse K1111111111Item A$7.2183,46978,000$3.8247.0%$5.5622.9%
Supplier DWarehouse K1111111111Item A$5.6383,46983,469$3.8232.1%$5.561.2%
Supplier EWarehouse K1111111111Item A$6.5683,46983,469$3.8241.8%$5.5615.2%
Supplier FWarehouse K1111111111Item A$6.0183,46983,000$3.8236.4%$5.567.5%
Supplier GWarehouse K1111111111Item A$5.7283,46983,469$3.8233.2%$5.562.8%
Supplier HWarehouse K2222222222Item A$5.6083,46983,469$3.8231.8%$5.560.7%
Supplier AWarehouse K2222222222Item B$6.1844,60244,602$6.111.1%$6.180.0%
Supplier BWarehouse K2222222222Item B$6.3544,60244,602$6.113.8%$6.182.7%
Supplier CWarehouse K2222222222Item B$6.5044,60244,602$6.116.0%$6.184.9%
Supplier DWarehouse K2222222222Item B$6.2244,60244,602$6.111.8%$6.180.6%
Supplier EWarehouse K2222222222Item B$6.6744,60244,602$6.118.4%$6.187.3%
Supplier FWarehouse K2222222222Item B$6.6144,60244,000$6.117.6%$6.186.5%
Supplier GWarehouse K2222222222Item B$6.2844,60244,602$6.112.7%$6.181.6%
Supplier HWarehouse K2222222222Item B$6.1144,60244,602$6.110.0%$6.18-1.1%

@Cday21,

 

It appears that the provided DAX doesn't work in Power Pivot but it does work in Power BI Desktop (what I'm using). You could explore the Power Query equivalent of this DAX (check the Power Query forum for posts on this topic).





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.