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
Saxon202202
Helper III
Helper III

Lookupvalue Return Max Value

I have two tables named "Data" and "Report."
The Data table comprises columns such as Area Code, Type, Rack Length, Rack Width, Rack Height, and Volume, which is determined based on the rack dimensions.
In the Report table, there are columns like Item, Area Code, Pack Length, Pack Width, and Height, with the Area Code serving as a key relationship linking the two tables.

In the context of the Data table, my goal is to determine the suitable rack size based on the pack dimensions associated with a specific area code.
To aid in this, I created a volume helper column in the Data table using the rack dimensions.

The primary purpose of this helper column is to identify the minimum volume when multiple sizes are matched.
For instance, it is designed to pinpoint the rack with the smallest volume among three racks capable of accommodating one of the boxes out of the twelve available.

Currently, I am exploring the possibility of a DAX code to create a new calculated column that achieves the same result.

To achieve this in Excel, I employ the following formula:
=IFERROR(LOOKUP(2,1/(DATA!$F$2:$F$15=1/(1/MAX(((DATA!$C$2:$C$15>=$D2)*(DATA!$D$2:$D$15>=$C2)+(DATA!$C$2:$C$15>=$C2)*(DATA!$D$2:$D$15>=$D2)>0)*(DATA!$E$2:$E$15>=$E2)*(DATA!$A$2:$A$15=$B2)*DATA!$F$2:$F$15))),DATA!$C$2:$C$15),"")

Report:

Saxon202202_1-1701901670475.png

 

Data:

Saxon202202_2-1701901714556.png


PBI:

Saxon202202_3-1701902082489.png


File attached for your reference

https://www.dropbox.com/scl/fi/hbrz1w0qglv7oe35vw5sx/NFS-SP-06-12-2023.pbix?rlkey=hifyzqbz5rlkqyly9r...
https://www.dropbox.com/scl/fi/xd8m5cjfux1y0oa1pitxw/SP-06.12.2023.xlsx?rlkey=zvhnmk6q4epu19jshlvhcb...


1 ACCEPTED SOLUTION

Hi,

Try this calculated column formula

Volume = CALCULATE(MAX(DATA[Volume]),FILTER(DATA,(DATA[Area Code]=EARLIER(REPORT[Area Code])&&DATA[Width]>=EARLIER(REPORT[Pack Width])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Length]))||(DATA[Area Code]=EARLIER(REPORT[Area Code])&&DATA[Width]>=EARLIER(REPORT[Pack Length])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Width]))))

Hope this helps.

Ashish_Mathur_0-1702003766408.png

 


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

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

Write these calculated column formulas in the Report table

 

Volume = CALCULATE(MAX(DATA[Volume]),FILTER(DATA,DATA[Area Code]=EARLIER(REPORT[Area Code])&&(DATA[Width]>=EARLIER(REPORT[Pack Width])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Length]))||(DATA[Width]>=EARLIER(REPORT[Pack Length])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Width]))))
Rack width = LOOKUPVALUE(DATA[Width],DATA[Area Code],REPORT[Area Code],DATA[Volume],REPORT[Volume])
Rack height = LOOKUPVALUE(DATA[Height],DATA[Area Code],REPORT[Area Code],DATA[Volume],REPORT[Volume])
Rack depth = LOOKUPVALUE(DATA[Depth],DATA[Area Code],REPORT[Area Code],DATA[Volume],REPORT[Volume])

 

Hope this helps.


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

@Ashish_Mathur , 
Thank you for your response. While the DAX code functions correctly when dealing with multiple area codes in the report table, it encounters issues when handling specific area codes, resulting in inaccurate outcomes. For instance,when the area code is "AB1" in the report table, the expected volume is 9 or 11.
However, the DAX code returns volumes associated with different area codes.
Among the total 7847 line items in the report table, 5352 align perfectly, but 2492 exhibit incorrect results. Despite my attempts to adjust the DAX code, it continues to produce errors.

incorrect Result:

Saxon202202_1-1701988648689.png

Can you assist me, please?
I have attached a file for your perusal.

https://www.dropbox.com/scl/fi/qrburmfeh65i8n521r3m6/Lookup2-1-Issue_07-12-2023.pbix?rlkey=o6w19w25w...
https://www.dropbox.com/scl/fi/1um93fj1lp0oxli9k6bpv/SP-07.12.2023.xlsx?rlkey=5n91yq2p85fiiw11k4t3qm...

Hi,

Try this calculated column formula

Volume = CALCULATE(MAX(DATA[Volume]),FILTER(DATA,(DATA[Area Code]=EARLIER(REPORT[Area Code])&&DATA[Width]>=EARLIER(REPORT[Pack Width])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Length]))||(DATA[Area Code]=EARLIER(REPORT[Area Code])&&DATA[Width]>=EARLIER(REPORT[Pack Length])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Width]))))

Hope this helps.

Ashish_Mathur_0-1702003766408.png

 


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

@Ashish_Mathur ,
Thank you for your response once more, and I apologize for the delayed reply.
Can you provide a quick tip on including extra filter criteria within your impressive DAX code?
I want the same resut by applying one more additionl filter criteria which is "Mode". If I have more thn one filter criteria can I apply next to area code for both place? It will work? The "Mode" filter criteria need to be apply next to the area code for both place? (Highlighted in red squre.
Data:

Saxon202202_0-1702476668871.png

Report:

Saxon202202_1-1702476719560.pngSaxon202202_2-1702476769258.png

https://www.dropbox.com/scl/fi/npbwfs3w42ifduzfevmgh/Lookup2-1_1312.pbix?rlkey=jejbnod00zrrj2dgchurf...
https://www.dropbox.com/scl/fi/xd8m5cjfux1y0oa1pitxw/SP-06.12.2023.xlsx?rlkey=zvhnmk6q4epu19jshlvhcb...

Yes, you can.  Please try it yourself.


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

@Ashish_Mathur ,
I appreciate your response. I've followed your suggestion and applied the filter after the type. Could you please confirm if this is the correct method for applying the additional filter criteria?


Saxon202202_0-1702577852054.png

Volume with Mode = CALCULATE(MAX(DATA[Volume]),FILTER(DATA,(DATA[Area Code]=EARLIER(REPORT[Area Code])&&(DATA[Mode])=EARLIER(REPORT[Mode])&&DATA[Width]>=EARLIER(REPORT[Pack Width])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Length]))||(DATA[Area Code]=EARLIER(REPORT[Area Code])&&(DATA[Mode])=EARLIER(REPORT[Mode])&&DATA[Width]>=EARLIER(REPORT[Pack Length])&&DATA[Height]>=EARLIER(REPORT[Pack Height])&&DATA[Depth]>=EARLIER(REPORT[Pack Width]))))

If you get the correct answer, then it is the right formula.


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

its great that you  have provided the data, but can you please rather provide the logic / business rule for the columns rather than providing the excel formula which is difficult to read. 

 

also in the report table, you have a column called type where does that column come from?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg, thank you for your reply.

 

Basically the small pack data need to be found smaller rack rather than going to bigger rack. 

based on what combination, need confirmation, do you only use area code?  if you use item and type, how do those link between the tables?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

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!

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.