Forum Discussion
Custom Ranking for Sorting
- 2 years ago
I fixed it - here is the simple solution: so the issue is just on simple KEEPFILTERS in the right place. Check that in VAR PriceForReturn. I chose to publish a lengthy version of the code with additional VARS to make it more readable for entry level DAX enthusiasts - like me 🙂
Measure = VAR SelectedId = SELECTEDVALUE('contracts'[RefId]) VAR IdSubset = ADDCOLUMNS ( CALCULATETABLE ( 'contracts', 'contracts'[Type] IN { "Change Milestone", "Milestone", "Change Project", "Project" } && NOT ISBLANK ( 'contracts'[EK] ) && 'contracts'[CreatedAtDate] <= MAX ( 'contracts_PersonSkillMap'[CreatedAtDate] ) && 'contracts'[RefId] = SelectedMitarbeiter ), "RankBy", COMBINEVALUES(" ", FORMAT ( 'contracts'[CreatedAtDate], "yyyyMMdd" ), SWITCH ( 'contracts'[Type], "Change Milestone", "4", "Change Project", "3", "Project", "2", "Contract", "1", "0" ), 'contracts'[Price] ), "Price Value", 'contracts'[Price] ) VAR RankByForFilter = MAXX(IdSubset,[Rankby]) VAR PriceForReturn = MAXX( FILTER( KEEPFILTERS(IdSubset), [RankBy] = RankByForFilter ), [Price Value] ) RETURN PriceForReturn
When you are new to DAX, coming from SQL, you have a lot to learn. Up to now I only considered that context is a big thing in DAX. Now I learned how essential - and at the same time tricky - context is.
Open is if I really need to add "Price Value" to the IdSubset... or if I could just return
I fixed it - here is the simple solution: so the issue is just on simple KEEPFILTERS in the right place. Check that in VAR PriceForReturn. I chose to publish a lengthy version of the code with additional VARS to make it more readable for entry level DAX enthusiasts - like me 🙂
Measure =
VAR SelectedId =
SELECTEDVALUE('contracts'[RefId])
VAR IdSubset =
ADDCOLUMNS (
CALCULATETABLE (
'contracts',
'contracts'[Type] IN { "Change Milestone", "Milestone", "Change Project", "Project" }
&& NOT ISBLANK ( 'contracts'[EK] )
&& 'contracts'[CreatedAtDate] <= MAX ( 'contracts_PersonSkillMap'[CreatedAtDate] )
&& 'contracts'[RefId] = SelectedMitarbeiter
),
"RankBy",
COMBINEVALUES(" ",
FORMAT ( 'contracts'[CreatedAtDate], "yyyyMMdd" ),
SWITCH (
'contracts'[Type],
"Change Milestone", "4",
"Change Project", "3",
"Project", "2",
"Contract", "1",
"0"
), 'contracts'[Price]
),
"Price Value",
'contracts'[Price]
)
VAR RankByForFilter = MAXX(IdSubset,[Rankby])
VAR PriceForReturn =
MAXX(
FILTER(
KEEPFILTERS(IdSubset),
[RankBy] = RankByForFilter
),
[Price Value]
)
RETURN
PriceForReturn
When you are new to DAX, coming from SQL, you have a lot to learn. Up to now I only considered that context is a big thing in DAX. Now I learned how essential - and at the same time tricky - context is.
Open is if I really need to add "Price Value" to the IdSubset... or if I could just return