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
vipett
Helper II
Helper II

Lookup based on Sum in Other Table & Certain criteras

I have two tables, one with Extra stock with certain attributes and one with my items. I try to find a suitable replacement article based on my list with "Extra stock".

The tables look roughly like this:

Extra stock (The tables Valid? in this example are all "Yes", but in real world they might be "No" as well

ItemNrAttribute 1Attribute 2Attribute 3A1 Valid?A2 Valid?A3 Valid?

S

tock Qty

Combo

ARedCarSolidYesYesYes50RedCarSolid
BBlueMopedTransparentYesYesYes500BlueMopedTransparent
CBlueMopedTransparentYesYesYes100BlueMopedTransparent

 

Items:

ItemNrAttribute 1Attribute 2Attribute 3StockAlternative ItemNrStock for AlternativeCombo
1RedCarSolid

10

  RedCarSolid
2BlueMopedTransparent20  BlueMopedTransparent
3OrangeMopedTransparent30  OrangeMopedTransparent
4GreenCarSolid40  GreenCarSolid

 

In the Items table, I want to display A as an alternative ItemNr for 1 with 50 in stock and for 2 I want B to be chosen (and when that stock is reduced below 100 then C should be the Alternative ItemNr.

 

There will be multiple combinations of the different attributes that don't have any stock.

When I try with Lookupvalue = 'Extra Stock'[ItemNr],[Stock quantity],Calculate(Max('Extra Stock'[Stock Quantity],_*My filters here*), Combo,Combo) I get "A single value for column Combo in Extra stock cannot be determined. [....].

 

What is the best way of doing this?

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @vipett ,

 

Here are the steps you can follow:

1. Create calculated column.

Alternative ItemNr =
VAR _Item =
    MAXX (
        FILTER (
            ALL ( 'Extra stock' ),
            'Extra stock'[Attribute 1] = EARLIER ( 'Items'[Attribute 1] )
                && 'Extra stock'[Attribute 2] = EARLIER ( 'Items'[Attribute 2] )
                && 'Extra stock'[Attribute 3] = EARLIER ( 'Items'[Attribute 3] )
                && 'Extra stock'[Stock Qty]
                    = MAXX (
                        FILTER (
                            ALL ( 'Extra stock' ),
                            'Extra stock'[Attribute 1] = EARLIER ( 'Extra stock'[Attribute 1] )
                                && 'Extra stock'[Attribute 2] = EARLIER ( 'Extra stock'[Attribute 2] )
                                && 'Extra stock'[Attribute 3] = EARLIER ( 'Extra stock'[Attribute 3] )
                        ),
                        'Extra stock'[Stock Qty]
                    )
        ),
        'Extra stock'[ItemNr]
    )
RETURN
    IF (
        _Item = BLANK ()
            && 'Items'[Stock] <= 100,
        MAXX (
            FILTER ( ALL ( 'Extra stock' ), 'Extra stock'[Stock Qty] = 100 ),
            'Extra stock'[ItemNr]
        ),
        _Item
    )
Stock for Alternative =
VAR _Item =
    MAXX (
        FILTER (
            ALL ( 'Extra stock' ),
            'Extra stock'[Attribute 1] = EARLIER ( 'Items'[Attribute 1] )
                && 'Extra stock'[Attribute 2] = EARLIER ( 'Items'[Attribute 2] )
                && 'Extra stock'[Attribute 3] = EARLIER ( 'Items'[Attribute 3] )
                && 'Extra stock'[Stock Qty]
                    = MAXX (
                        FILTER (
                            ALL ( 'Extra stock' ),
                            'Extra stock'[Attribute 1] = EARLIER ( 'Extra stock'[Attribute 1] )
                                && 'Extra stock'[Attribute 2] = EARLIER ( 'Extra stock'[Attribute 2] )
                                && 'Extra stock'[Attribute 3] = EARLIER ( 'Extra stock'[Attribute 3] )
                        ),
                        'Extra stock'[Stock Qty]
                    )
        ),
        'Extra stock'[Stock Qty]
    )
RETURN
    IF (
        _Item = BLANK ()
            && 'Items'[Stock] <= 100,
        MAXX (
            FILTER ( ALL ( 'Extra stock' ), 'Extra stock'[Stock Qty] = 100 ),
            'Extra stock'[Stock Qty]
        ),
        _Item
    )

2. Result:

vyangliumsft_0-1678261587204.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
v-yangliu-msft
Community Support
Community Support

Hi  @vipett ,

 

Here are the steps you can follow:

1. Create calculated column.

Alternative ItemNr =
VAR _Item =
    MAXX (
        FILTER (
            ALL ( 'Extra stock' ),
            'Extra stock'[Attribute 1] = EARLIER ( 'Items'[Attribute 1] )
                && 'Extra stock'[Attribute 2] = EARLIER ( 'Items'[Attribute 2] )
                && 'Extra stock'[Attribute 3] = EARLIER ( 'Items'[Attribute 3] )
                && 'Extra stock'[Stock Qty]
                    = MAXX (
                        FILTER (
                            ALL ( 'Extra stock' ),
                            'Extra stock'[Attribute 1] = EARLIER ( 'Extra stock'[Attribute 1] )
                                && 'Extra stock'[Attribute 2] = EARLIER ( 'Extra stock'[Attribute 2] )
                                && 'Extra stock'[Attribute 3] = EARLIER ( 'Extra stock'[Attribute 3] )
                        ),
                        'Extra stock'[Stock Qty]
                    )
        ),
        'Extra stock'[ItemNr]
    )
RETURN
    IF (
        _Item = BLANK ()
            && 'Items'[Stock] <= 100,
        MAXX (
            FILTER ( ALL ( 'Extra stock' ), 'Extra stock'[Stock Qty] = 100 ),
            'Extra stock'[ItemNr]
        ),
        _Item
    )
Stock for Alternative =
VAR _Item =
    MAXX (
        FILTER (
            ALL ( 'Extra stock' ),
            'Extra stock'[Attribute 1] = EARLIER ( 'Items'[Attribute 1] )
                && 'Extra stock'[Attribute 2] = EARLIER ( 'Items'[Attribute 2] )
                && 'Extra stock'[Attribute 3] = EARLIER ( 'Items'[Attribute 3] )
                && 'Extra stock'[Stock Qty]
                    = MAXX (
                        FILTER (
                            ALL ( 'Extra stock' ),
                            'Extra stock'[Attribute 1] = EARLIER ( 'Extra stock'[Attribute 1] )
                                && 'Extra stock'[Attribute 2] = EARLIER ( 'Extra stock'[Attribute 2] )
                                && 'Extra stock'[Attribute 3] = EARLIER ( 'Extra stock'[Attribute 3] )
                        ),
                        'Extra stock'[Stock Qty]
                    )
        ),
        'Extra stock'[Stock Qty]
    )
RETURN
    IF (
        _Item = BLANK ()
            && 'Items'[Stock] <= 100,
        MAXX (
            FILTER ( ALL ( 'Extra stock' ), 'Extra stock'[Stock Qty] = 100 ),
            'Extra stock'[Stock Qty]
        ),
        _Item
    )

2. Result:

vyangliumsft_0-1678261587204.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

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.