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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Quinn
Frequent Visitor

How to get the data from other table by filter

I have 2 tables, and I need DAX to help me get data from Price table to Order table. The "Customer" ,"Plant" ,"Material" in Order table must matched with Price table , and "ETD" should within valid from and valid to, then we can find the correct price.

I try to use below DAX it can get the correct data, but my team member said we cannot use MAXX function, since it's to find the maximum value. Is there any other Dax can help me to get the result?

Quinn_0-1691570633375.png

Quinn_2-1691570741377.png

 

 

2 ACCEPTED SOLUTIONS
v-shex-msft
Community Support
Community Support

Hi @Quinn,

In fact, Maxx or other aggregated functions can be used to lookup value from another table.
You can modify the conditions to get one result and it should be the value that you want, or it will return the aggregate value from results that match with conditions.

formula =
VAR currCustomer =
    SELECTEDVALUE ( Order[Customer] )
VAR currPlant =
    SELECTEDVALUE ( Order[Plant] )
VAR currPN =
    SELECTEDVALUE ( Order[PN] )
VAR currDate =
    MAX ( Order[ETD] )
RETURN
    MAXX (
        FILTER (
            ALLSELECTED ( 'Price' ),
            [Customer] = currCustomer
                && [Plant] = currPlant
                && [Material] = currPN
                && AND ( currDate >= [Valid From], currDate <= [Valid To] )
        ),
        [Condition Amount]
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the Order Table

Correct Price = calculate(max(Price[Condition amount]),filter(Price,Price[Customer]=earlier(Order[Customer])&&Price[Plant]=earlier(Order[Plant])&&Price[Material]=earlier(Order[PN])&&Price[Valid from]<=earlier(Order[ETD])&&Price[Valid To]>=earlier(Order[ETD])))

Hope this helps.


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the Order Table

Correct Price = calculate(max(Price[Condition amount]),filter(Price,Price[Customer]=earlier(Order[Customer])&&Price[Plant]=earlier(Order[Plant])&&Price[Material]=earlier(Order[PN])&&Price[Valid from]<=earlier(Order[ETD])&&Price[Valid To]>=earlier(Order[ETD])))

Hope this helps.


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

Hi,

thanks for your help.

May I know what's the meaning of "earlier", why we should put it in each item first? and if I want to change the "Price[Valid from]<=earlier(Order[ETD])" to Price[Valid from] <= today (), how to write the dax?

Thank you.

You are welcome.  EARLIER() can be interpeted as "current row".  Write it exactly that way.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-shex-msft
Community Support
Community Support

Hi @Quinn,

In fact, Maxx or other aggregated functions can be used to lookup value from another table.
You can modify the conditions to get one result and it should be the value that you want, or it will return the aggregate value from results that match with conditions.

formula =
VAR currCustomer =
    SELECTEDVALUE ( Order[Customer] )
VAR currPlant =
    SELECTEDVALUE ( Order[Plant] )
VAR currPN =
    SELECTEDVALUE ( Order[PN] )
VAR currDate =
    MAX ( Order[ETD] )
RETURN
    MAXX (
        FILTER (
            ALLSELECTED ( 'Price' ),
            [Customer] = currCustomer
                && [Plant] = currPlant
                && [Material] = currPN
                && AND ( currDate >= [Valid From], currDate <= [Valid To] )
        ),
        [Condition Amount]
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.