Forum Discussion
pjr1221
7 years agoFrequent Visitor
Add Column with DAX function
Hello All, How can I add column using DAX? I don't know what function to use in DAX. Here is sample table,I can't show my real table because it's too big. ...
- 7 years ago
Edited:
I took the last line away. That was causing the variant data type error. You haven't described what you need if the result is neither >20% above or <20% below. The code below returns blank in those cases. If that's no what you need update it accordingly.
GAP_v2 = VAR _ValuePreviousWeek = CALCULATE ( DISTINCT ( Table1[Value] ); ALLEXCEPT ( Table1; Table1[ID] ); Table1[WEEK] = EARLIER ( Table1[WEEK] ) - 1 ) RETURN IF (NOT ISBLANK ( _ValuePreviousWeek ); VAR _Perc = DIVIDE ( Table1[VALUE] - _ValuePreviousWeek; _ValuePreviousWeek ) RETURN SWITCH ( TRUE (); _Perc >= 120 / 100; "Increase"; _Perc <= 80 / 100; "Decrease"
) )
AlB
Community Champion
7 years agoEdited:
I took the last line away. That was causing the variant data type error. You haven't described what you need if the result is neither >20% above or <20% below. The code below returns blank in those cases. If that's no what you need update it accordingly.
GAP_v2 =
VAR _ValuePreviousWeek =
CALCULATE (
DISTINCT ( Table1[Value] );
ALLEXCEPT ( Table1; Table1[ID] );
Table1[WEEK]
= EARLIER ( Table1[WEEK] ) - 1
)
RETURN
IF (NOT ISBLANK ( _ValuePreviousWeek );
VAR _Perc =
DIVIDE ( Table1[VALUE] - _ValuePreviousWeek; _ValuePreviousWeek )
RETURN
SWITCH (
TRUE ();
_Perc >= 120 / 100; "Increase";
_Perc <= 80 / 100; "Decrease"
)
)