Forum Discussion
Relate two table without a Key with conditional
- 4 years ago
Anonymous
Ok. Please tryNumber of Vehicles = VAR CurrentVolum = SELECTEDVALUE ( Salles[Volume] ) VAR MAXCapacity = MAX ( Carriers[CAPACIDADE DE] ) RETURN IF ( NOT ISBLANK( CurrentVolum ), ROUNDUP ( DIVIDE ( CurrentVolum, MAXCapacity ), 0 ) )
Hi Anonymous
Of course, I want the formula brings "Carreta" that is the biggest truck, I know afertr that I'll need to divide "Volume"/ "Capacidade até" to find a quantitity of trucks I'll nedd. But for now I need bring the truck first.
Look the exemple bellow, in this case a need show "Toco". Because Is equivalent at weight range of Carrier "Jadlog" from the City "Campinas"
Anonymous , let me see if I understand the logic.
For the first example, we have in Table 1 Volume =203682 and City = Barueri.
So we search Table 2 for rows that have City = Barueri and choose the row with the highest [Capacidade até].
That row has [Capacidade até] = 14000 and has [Tipo] = Carreta, so Carreta is the desired result.
I will apply the same logic to example 2: we have in Table 1 Volume =1473 and City = Campinas.
So we search Table 2 for rows that have City = Campinas and choose the row with the highest [Capacidade até].
That row has [Capacidade até] = 6800 and has [Tipo] = Carreta, so Carreta is the desired result. But you say it should be "Toco".
I do not understand the logic you are trying to acheive. Can you explain more clearly please with a few more examples?
Edit: OK, I think I understand it better now that you've posted more data.
You want to find the [Tipo] from Table 2 with the same [City] and where [Volume] is between [Capacidade de] and [Capacidade até]. If there is no row, then pick the [Tipo] from Table 2 with the [City] with the highest [Capacidade até].
This measure should achieve it:
Calculated Tipo =
VAR vCity = SELECTEDVALUE('Table2'[City])
VAR vVolume = SELECTEDVALUE('Table2'[Volume])
VAR vTipoInRange =
MAXX(
TOPN(
1,
FILTER(
'Table1',
'Table1'[City] = vCity
&& vVolume >= 'Table1'[CAPACIDADE_DE]
&& vVolume <= 'Table1'[CAPACIDADE_Ate]
),
'Table1'[CAPACIDADE_DE], ASC
),
'Table1'[TIPO]
)
VAR vHighestCapacityTipo =
MAXX(
TOPN(
1,
FILTER(
'Table1',
'Table1'[City] = vCity
),
'Table1'[CAPACIDADE_Ate], DESC
),
'Table1'[TIPO]
)
RETURN
COALESCE(vTipoInRange, vHighestCapacityTipo)
If the COALESCE function gives an error, then replace
COALESCE(vTipoInRange, vHighestCapacityTipo)with
IF(ISBLANK(vTipoInRange), vHighestCapacityTipo, vTipoInRange)
- Anonymous4 years agoNot applicable
Hi Anonymous , thanks so much for the help.
It's amoust working rsrsrs
I just didn't undestand why when the "Volume" is 0, it's returning "Carreta", look the replacement of names that I did, can you see any mistake?
If you need any more information, let'me know
Daniela Xavier