Forum Discussion
Issue to translate sql logic to dax
- 8 months ago
Hi k_h_s
et filtered EntityIDs from FactTable_A
FilteredEntities =
CALCULATETABLE(
VALUES(FactTable_A[EntityID]),
-- Add your business filters here
FactTable_A[SomeColumn] = "SomeValue"
)
Filter FactTable_B using these EntityIDsFilteredFactB =
FILTER(
FactTable_B,
FactTable_B[EntityID] IN FilteredEntities
&& FactTable_B[OtherStaticFilter] = "SomeValue"
)
Get latest row per EntityID + AttributeLatestFactB =
FILTER(
FilteredFactB,
RANKX(
FILTER(FilteredFactB,
FactTable_B[EntityID] = EARLIER(FactTable_B[EntityID]) &&
FactTable_B[Attribute] = EARLIER(FactTable_B[Attribute])
),
FactTable_B[Date],
,
DESC,
DENSE
) = 1
)Try these solutions and let me know if you need further clarification
Regards,
Rufyda Rahma | MIE - 8 months ago
Hi k_h_s - as per above mentioned, information do not remove filter context from FactTable_A.
you can try the below measue:
Latest FactB Date =
VAR EntityList =
VALUES ( FactTable_A[EntityID] )
RETURN
CALCULATE (
MAX ( FactTable_B[Date] ),
-- Static filters on FactTable_B
FactTable_B[OtherStaticFilter] = "SomeValue",
-- Apply Entity list from FactTable_A (SQL IN equivalent)
TREATAS (
EntityList,
FactTable_B[EntityID]
)
)Hope this helps.
Hi k_h_s - as per above mentioned, information do not remove filter context from FactTable_A.
you can try the below measue:
Latest FactB Date =
VAR EntityList =
VALUES ( FactTable_A[EntityID] )
RETURN
CALCULATE (
MAX ( FactTable_B[Date] ),
-- Static filters on FactTable_B
FactTable_B[OtherStaticFilter] = "SomeValue",
-- Apply Entity list from FactTable_A (SQL IN equivalent)
TREATAS (
EntityList,
FactTable_B[EntityID]
)
)
Hope this helps.