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
Nagarjunav
Frequent Visitor

How to get Minimum price Supplier name?

Hi Friends

 

This is Nagarjuna. I Have a small query, Can u please help me on this?

 

    *Required Column
Item CodeSupplier NameSupplier PriceItem Minimum PriceMinimum Price Supplier
101A11A
101B21A
101C31A
101D41A
101E51A
102F66F
102G76F
102H86F
102I96F
102J106F
102K116F
103L1212L
103M1312L
103N1412L
103O1512L
103P1612L
103Q1712L
103R1812L
104S1919S
104T2019S
104U2119S
104V2219S
104W2319S

 

How do i get the minimum price supplier name in a seperate column.

 

Thanks in advance 

Warm regards 

Nagarjuna

1 ACCEPTED SOLUTION

You can download the test file here: https://www.dropbox.com/s/gz881qnwd3dedfa/CheapestSupplier.pbix?dl=0

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

View solution in original post

14 REPLIES 14
Ashish_Mathur
Super User
Super User

Hi @Nagarjunav,

 

Can you answer my question please.  I believe you did post a reply but when i click on that link, i do not see your response.  Did you delete your response?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur

I was not deleted my post, i don't know why it has gone. I was reposted above please have a look

 

Thank you

Ok, but you forgot to tell us the most important thing: did you solve your scenario?

 

Thanks.


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

@AlbertoFerrari@Ashish_Mathur

 

No, i got an error while calculating 2nd formula i.e. 

VAR Suppliers =
    CALCULATETABLE (
        ADDCOLUMNS (
            VALUES ( Trans[Supplier Name] ),
            "SuppliedQty", CALCULATE ( SUM ( Trans[Qty] ) )
        ),
        ALLEXCEPT ( Trans, Trans[Item Code] ),
        Trans[Supplier Price] = MinPrice
    )

 

It is not working,  showing the below error.

 

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.

 

Can you please recheck the solution in Power BI, I mean can you provide the solution screenshot.

 

And one thing i want to tell you, In my case supplier price( I mean one supplier price) will be same for all transactions for that item code

 

Eg: Supplier A supplied at $1 for the item code 1001 . We may have 1000 transactions with supplier A for the item code 1001, but        he will supply at $1 only.

      Supplier C supplied at $3 for the item code 1001. We may have 2000 transaction with supplier C for the item code 1001, but          he will supply at $3 only.

 

Thank You

Regards

Nagarjuna

You can download the test file here: https://www.dropbox.com/s/gz881qnwd3dedfa/CheapestSupplier.pbix?dl=0

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

Thank you @AlbertoFerrari

 

I made a mistake that's  why i got an error, sorry for that.

 

Now its worked without error but i got blanks in some rows (Almost in 50% rows). Can you Please tell me what could be the reason?

 

Thank you

Regards

Nagarjuna

Without looking at the data? No way... Likely, there's a bug somewhere in the code, but I would need some test data to find it. If you can share some sample data where the errors spots, then I can take a look at it.

 


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

Thank you @AlbertoFerrari

 

Now its working, I changed formula according to my requirements.

 

Now i am checking with my report which i have done it in excel. If i found any deviations i will get back to you with the sample data, otherwise i will accept it as a solution.

 

Once again thank you so much 

Regards 
Nagarjuna

Hi @Ashish_Mathur, @AlbertoFerrari

 

Supplier price will be same for all transactions because i was added Average price column. My caluculations will be on average price only. Thedata was very big thats why i was given small data. If we get solution for this sample data thats enough for me.

 

First it should check for the lowest price supplier, if conflicts then only it should check the quantity.

 

And the supplier price (Particular supplier price) will same for all the transactions for that particular item

 

I was not deleted my post, i don't know why it was gone

 

Here is my original post.

 

Thank you Mr. Interkoubess, it worked perfectly when suppliers supplied at unique prices. As told by the Ashish_Mathur there could be a chance that different suppliers can supply for the same price, in that case it is not working. It is showing the below error

 

A table of multiple values was supplied where a single value was expected.

 

Suppose if one item was supplied at the same price by the different suppliers, then the answer shall be the supplier who supplies more quantity and if the quantity is also same, any one of them is ok for me

 

Now i am changing the data for better understanding 

 

Please find the below table

 

      *Require Column
Transaction IDItem CodeSupplier NameSupplier PriceQtyItem Minimum PriceMinimum Price Supplier
11001A11001B
21001A12001B
31001B13501B
41001C31001B
51001C35001B
61001D41001B
71001E51001B
81002F61006F
91002F61006F
101002F61006F
111002G71006F
121002G71506F
131002G72006F
141002H83006F
151002H83006F
161002H83006F
171002I95006F
181002J103006F
191002K111006F
201003L1320012M
211003L1320012M
221003L1320012M
231003M1210012M
241003M1210012M
251003M1210012M
261003N1410012M
271003O1510012M
281003P1610012M
291003Q1710012M
301003R1810012M
311004S1910019U
321004S1910019U
331004S1920019U
341004T2020019U
351004U1920019U
361004U1920019U
371004V2230019U
381004W2340019U

 

For the item code 1001 the minimum price is 1,

Two suppliers A&B supplied at 1, 

B supplied 350 units but supplied only 300 units , So the answer should be "B" for item code 1001

 

For the item code 1002 the minimum price is 6,

Only supplier F supplied at 6, So the answer should be "F"  for the item code 1002

 

For the item code 1003 the minimum price is 12,

Only supplier M supplied at 12, so the answer should be "M" for the item code 1003

 

For the item code 1004 the minimum price is 19

Two Suppliers S&U supplied at 19,

Both suppliers supplied the same quantity of 400 units, in that case answer shall be S/U, but it should same for all the transactions

 

Please let me know if clarification needed?

 

Thanks in advance

Regards 

Nagarjuna

I think he removed it. I was answering that post (he published some data with duplicates, that made the problem much more interesting) and the forum told me the message was no longer there. Thus, I replied to the main topic, even if I used data from that deleted message to do some tests.

 


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

Well, that was a nice one!

 

This works as a calculated column, it is somewhat intricated, but it will return the first supplier based on the quantity sold and the supplier name who sold at the min price:

 

CheapestSupplier =
VAR MinPrice =
    CALCULATE (
        MIN ( Trans[Supplier Price] ),
        ALLEXCEPT ( Trans, Trans[Item Code] )
    )
VAR Suppliers =
    CALCULATETABLE (
        ADDCOLUMNS (
            VALUES ( Trans[Supplier Name] ),
            "SuppliedQty", CALCULATE ( SUM ( Trans[Qty] ) )
        ),
        ALLEXCEPT ( Trans, Trans[Item Code] ),
        Trans[Supplier Price] = MinPrice
    )
VAR TopSupplier =
    TOPN ( 1, Suppliers, [SuppliedQty], DESC, Trans[Supplier Name], ASC )
RETURN
    CONCATENATEX ( TopSupplier, Trans[Supplier Name], ", " )

Please note that the quantity sold does not depend on the price, supplier A might have sold you something at 200, then some at 300 and the two values will be summed together to determine if he's the best one.

 

Youc an adapt it to consider only the quantity at the lowest price, or modify the code to compute slightly differnt calculations, the core should remain the same.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI
Nagarjunav
Frequent Visitor

Thank you Mr. Interkoubess, it worked perfectly when suppliers supplied at unique prices. As told by the Ashish_Mathur there could be a chance that different suppliers can supply for the same price, in that case it is not working. It is showing the below error

 

A table of multiple values was supplied where a single value was expected.

 

Suppose if one item was supplied at the same price by the different suppliers, then the answer shall be the supplier who supplies more quantity and if the quantity is also same, any one of them is ok for me

 

Now i am changing the data for better understanding 

 

Please find the below table

 

      *Require Column
Transaction IDItem CodeSupplier NameSupplier PriceQtyItem Minimum PriceMinimum Price Supplier
11001A11001B
21001A12001B
31001B13501B
41001C31001B
51001C35001B
61001D41001B
71001E51001B
81002F61006F
91002F61006F
101002F61006F
111002G71006F
121002G71506F
131002G72006F
141002H83006F
151002H83006F
161002H83006F
171002I95006F
181002J103006F
191002K111006F
201003L1320012M
211003L1320012M
221003L1320012M
231003M1210012M
241003M1210012M
251003M1210012M
261003N1410012M
271003O1510012M
281003P1610012M
291003Q1710012M
301003R1810012M
311004S1910019U
321004S1910019U
331004S1920019U
341004T2020019U
351004U1920019U
361004U1920019U
371004V2230019U
381004W2340019U

 

For the item code 1001 the minimum price is 1,

Two suppliers A&B supplied at 1, 

B supplied 350 units but supplied only 300 units , So the answer should be "B" for item code 1001

 

For the item code 1002 the minimum price is 6,

Only supplier F supplied at 6, So the answer should be "F"  for the item code 1002

 

For the item code 1003 the minimum price is 12,

Only supplier M supplied at 12, so the answer should be "M" for the item code 1003

 

For the item code 1004 the minimum price is 19

Two Suppliers S&U supplied at 19,

Both suppliers supplied the same quantity of 400 units, in that case answer shall be S/U, but it should same for all the transactions

 

Please let me know if clarification needed?

 

Thanks in advance

Regards 

Nagarjuna

 

 

 

Ashish_Mathur
Super User
Super User

Hi,

 

Can there be a case where the minimum price is the same for the same Item code but supplied by different suppliers.  For e.g. supplier A and C both have a price of 1for item code 101.  If this is a possibility, then what result would you want?  Please clarify.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Interkoubess
Solution Sage
Solution Sage

Hi @Nagarjunav,

 

Please try this measure with my table named Data:

 

Test =
LOOKUPVALUE (
    Data[Supplier Name],
    Data[Supplier Price], MIN ( Data[Item Minimum Price] )
)

Please ley us know if you have any observations...

 

test.PNG

 

Ninter

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.

Top Solution Authors