Forum Discussion
massotebernoull
Helper I
4 years agoGetting the latest value from two tables
Hi, I tried in a different ways, but I'm strugled with this: I have the Opportunities table and Appointments table, as it follows: Opportunities table CUSTOMER createdon STATUS A 08/03/2...
- 4 years ago
Hi,
Please check the below picture and the attached pbix file.
From Opportunities CC = VAR currentyear = YEAR ( Appointment[VISIT DATE] ) VAR currentcustomer = Appointment[CUSTOMER] VAR opptable_bymaxdateyear = CALCULATETABLE ( Opportunities, TREATAS ( SELECTCOLUMNS ( GROUPBY ( ADDCOLUMNS ( Opportunities, "@year", YEAR ( Opportunities[createdon] ) ), Opportunities[CUSTOMER], [@year], "@maxdate_peryear", MAXX ( CURRENTGROUP (), Opportunities[createdon] ) ), "@customer", Opportunities[CUSTOMER], "@create", [@maxdate_peryear] ), Opportunities[CUSTOMER], Opportunities[createdon] ) ) VAR filtertable = FILTER ( opptable_bymaxdateyear, YEAR ( Opportunities[createdon] ) = currentyear && Opportunities[CUSTOMER] = currentcustomer ) RETURN IF ( NOT ISBLANK ( MAXX ( filtertable, Opportunities[STATUS] ) ), MAXX ( filtertable, Opportunities[STATUS] ), "No Opportunity" )
Jihwan_Kim
Super User
4 years agoHi,
Please check the below picture and the attached pbix file.
From Opportunities CC =
VAR currentyear =
YEAR ( Appointment[VISIT DATE] )
VAR currentcustomer = Appointment[CUSTOMER]
VAR opptable_bymaxdateyear =
CALCULATETABLE (
Opportunities,
TREATAS (
SELECTCOLUMNS (
GROUPBY (
ADDCOLUMNS ( Opportunities, "@year", YEAR ( Opportunities[createdon] ) ),
Opportunities[CUSTOMER],
[@year],
"@maxdate_peryear", MAXX ( CURRENTGROUP (), Opportunities[createdon] )
),
"@customer", Opportunities[CUSTOMER],
"@create", [@maxdate_peryear]
),
Opportunities[CUSTOMER],
Opportunities[createdon]
)
)
VAR filtertable =
FILTER (
opptable_bymaxdateyear,
YEAR ( Opportunities[createdon] ) = currentyear
&& Opportunities[CUSTOMER] = currentcustomer
)
RETURN
IF (
NOT ISBLANK ( MAXX ( filtertable, Opportunities[STATUS] ) ),
MAXX ( filtertable, Opportunities[STATUS] ),
"No Opportunity"
)
- massotebernoull4 years ago
Helper I
Thank you!! It works perfectly