Forum Discussion
Make DAX code dynamic instead of hard-coded
Inflow jaarweek v5 =
IF(
// Blank is treated as 0 in ADX,
// so (BLANK = 0) is true but
// (BLANK == 0) is false.
SUM( Contracthistorie[IsInflowWeek] ) <> 0,
var CurrentSeqNo =
SELECTEDVALUE( 'Dates'[MonthSeqNo] )
var IsLastWeekInYear =
int( SELECTEDVALUE( 'Dates'[MonthSeqNoInYear] ) = 53 )
var Result =
CALCULATE(
SUM( Contracthistorie[IsInflowWeek] ),
'Dates'[MonthSeqNo] = CurrentSeqNo + 1,
// If it's true that the field
// [Is start contract peilweek] can only
// hold 1 and 0 (as it should be since
// it's a boolean column), then this
// whole formula can be reduced to
// what you see here. Please make sure
// you don't store any BLANKs in the
// column. And if the model is correct,
// you should not have BLANKs here.
'Dates'[Is start contract peilweek]
in {1, 1 - IsLastWeekInYear},
ALL( 'Dates' )
)
RETURN
Result
)
- RobinNeven4 years agoHelper I
Hi Anonymous ,
Thanks for your reply! I tried a couple of variations of your code trying to come up with the right one. But haven't figured it out just quite yet.
I'm assuming that where you say 'MonthSeqNoInYear' you actually mean 'WeekSeqNoInYear' given that it's followed by "= 53"? And in that same fashion I think you mean 'WeekSeqNo' instead of 'MonthSeqNo' elsewhere in the code?
If so, it would look like the following to use the right field names for my model:
Inflow jaarweek v6 = IF( // Blank is treated as 0 in ADX, // so (BLANK = 0) is true but // (BLANK == 0) is false. SUM( Contracthistorie[IsInflowWeek] ) <> 0, var CurrentSeqNo = SELECTEDVALUE( 'Contract peildatum'[Contract peilweek order] ) var IsLastWeekInYear = int( SELECTEDVALUE( 'Contract peildatum'[Contract peilweek order]) = 53 ) var Result = CALCULATE( SUM( Contracthistorie[IsInflowWeek] ), 'Contract peildatum'[Contract peilweek order] = CurrentSeqNo + 1, // If it's true that the field // [Is start contract peilweek] can only // hold 1 and 0 (as it should be since // it's a boolean column), then this // whole formula can be reduced to // what you see here. Please make sure // you don't store any BLANKs in the // column. And if the model is correct, // you should not have BLANKs here. 'Contract peildatum'[Is start contract peilweek] in {1, 1 - IsLastWeekInYear}, ALL( 'Contract peildatum' ) ) RETURN Result )And this works in the sense that it gives no errors and gives back the same results as my v4 version of the measure. But it doesn't give the result that i'm looking for similar to v3 (but dynamically) unfortunately. Am I missing something?
Thanks again!
- daxer-almighty4 years agoSolution Sage
Since I don't know your model and all I've been doing is guessing as best as I could, it might be that you need to adjust something in the measure I gave you to make it work in your case. I can't help you more than I have due to me not knowing your model and data. All you have to do is take the framework I've shown here and make it suitable for your case.