cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lalTel20
Helper I
Helper I

Using dax to get latest value from another table

I'd like to update table A with values from Table B.
Requirement - to update the latest [Value] based on [Created] where [value] contains 'Quote'.
Catch is, if on the same date quote is sent and approved, then table A needs to be updated with Quote Approved. What is the best way to get the desired outcome.

Quote_Sub = 
VAR CaseNumber = 'A'[CASE NUMBER]
VAR SUB_Table =
    CALCULATETABLE (
        SELECTCOLUMNS (
            FILTER ( B, B[Case Number] = CaseNumber ),
            "Start Date", B[Created],
            "Sub Value", B[Value]
        ),
        CONTAINSSTRING ( DCM_METRIC_INSTANCE[Value], "Quote" )
    )
VAR Quote_A = MAXX(FILTER(SUB_Table, [Sub Value] = "Quote Approved"),[Start Date])
VAR Quote_Ex = MAXX(FILTER(SUB_Table, [Sub Value] = "Quote Expired"),[Start Date])
VAR Quote_R = MAXX(FILTER(SUB_Table, [Sub Value] = "Quote Rejected"),[Start Date])
VAR Quote_Es = MAXX(FILTER(SUB_Table, [Sub Value] = "Quote Escalated"),[Start Date])
VAR Quote_S = MAXX(FILTER(SUB_Table, [Sub Value] = "Quote Sent"),[Start Date])

VAR max_date = MAXX({Quote_A,Quote_Ex,Quote_R,Quote_Es,Quote_S}, [Value])
VAR max_value = 
calculatetable(
    FIRSTNONBLANK(SELECTCOLUMNS( FILTER(SUB_Table,[Start Date]=max_date),
"max Value",[Sub Value]),[max Value])
)
return max_value

 

lalTel20_0-1649048752728.pnglalTel20_1-1649048766597.png

 

1 ACCEPTED SOLUTION
yingyinr
Community Support
Community Support

Hi @lalTel20 ,

You can create a calculated column as below in table A, please find the details in the attachment.

Quote_Sub =
VAR _acnum = 'A'[CASE NUMBER]
VAR _maxdate =
CALCULATE ( MAX ( 'B'[Created] ), FILTER ( 'B', 'B'[CASE NUMBER] = _acnum ) )
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'B'[VALUE] ),
FILTER (
'B',
'B'[CASE NUMBER] = _acnum
&& 'B'[VALUE]
IN { "Quote Approved", "Quote Sent" }
&& 'B'[Created] = _maxdate
)
)
RETURN
IF ( _count = 2, "Quote Approved", 'A'[Value] )

yingyinr_0-1649317979224.png

If the above one is not your expected one, please provide some sample data (exclude sensitive data) in the table A and B with Text format and your expected resultwith backend logic and special examples. It is better if you can share a simplified pbix file with me. You can refer the following thread to upload your file in the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
yingyinr
Community Support
Community Support

Hi @lalTel20 ,

You can create a calculated column as below in table A, please find the details in the attachment.

Quote_Sub =
VAR _acnum = 'A'[CASE NUMBER]
VAR _maxdate =
CALCULATE ( MAX ( 'B'[Created] ), FILTER ( 'B', 'B'[CASE NUMBER] = _acnum ) )
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'B'[VALUE] ),
FILTER (
'B',
'B'[CASE NUMBER] = _acnum
&& 'B'[VALUE]
IN { "Quote Approved", "Quote Sent" }
&& 'B'[Created] = _maxdate
)
)
RETURN
IF ( _count = 2, "Quote Approved", 'A'[Value] )

yingyinr_0-1649317979224.png

If the above one is not your expected one, please provide some sample data (exclude sensitive data) in the table A and B with Text format and your expected resultwith backend logic and special examples. It is better if you can share a simplified pbix file with me. You can refer the following thread to upload your file in the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@lalTel20 , Is there a preference when date is the same

 

example measure

new column =
var _max = maxx(filter(Table, [casenumber] = earlier([casenumber]) ), [Created])
return
maxx(filter(Table, [casenumber] = earlier([casenumber]) && [Created] = _max), [Value])



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || Learn 50+ Power Query List Functions
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!

Hi @amitchandak 
Thank you for your response. Yes the preference is Quote sent gets the least preference, since after the quote is sent, it can be rejected, accepted, escalated or expired on the same day. And it is not always necessary that there will be a subsequent event for a casenumber. In such scenario the atest stage would be quote sent. 

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.