Forum Discussion
TOK
Helper II
4 years agoDAX Measure for previous values based on dimension
I am struggeling with creating a measure with DAX. I have an existing measure per two dimensions (ChainStoreID, ClusterID) Now I want my measure to follow two simple rules. 1. If there is a bl...
- 4 years ago
TOK
Try this https://www.dropbox.com/t/fEVKUullXZ43UnudNew Value = VAR CurrentValue = Data[Value] VAR CurrentClusterId = Data[ClusterId] VAR CurrentStoreTable = CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[ChainStoreId] ) ) VAR PreviousClustersTable = FILTER ( CurrentStoreTable, Data[ClusterId] < CurrentClusterId ) VAR MaxValuePerStore = MAXX ( PreviousClustersTable, Data[Value] ) VAR ClusterIdOfMaxValue = CALCULATE ( MAX ( Data[ClusterId] ), PreviousClustersTable, Data[Value] = MaxValuePerStore ) VAR Result = IF ( CurrentValue < MaxValuePerStore && CurrentClusterId > ClusterIdOfMaxValue, MaxValuePerStore, CurrentValue ) RETURN Result
Jihwan_Kim
Super User
4 years agoHi,
Please check the below picture and the attached pbix file.
Value measure: =
SUM( Data[Value] )
Desired outcome measure: =
VAR currentclusterid =
MAX ( 'Cluster'[ClusterID] )
VAR currentchainstoreid =
MAX ( ChainStore[ChainStoreID] )
VAR currentvalue = [Value measure:]
VAR maxvalueperchainstore =
MAXX (
FILTER (
ALL ( Data ),
Data[ChainStoreID] = currentchainstoreid
&& Data[ClusterID] <= currentclusterid
),
Data[Value]
)
RETURN
IF (
currentvalue <= maxvalueperchainstore,
maxvalueperchainstore,
currentvalue
)