Forum Discussion
Anonymous
4 years agoNot applicable
How to avoid hard coding Dax
Hi I have a table as follows CustID GroupID CustType Amount Group_CustType_Concat 1 1 Intermediate 10 1Intermediate 1 1 Intermediate 20 1Intermediate 2 3 Regular 30 3R...
- 4 years ago
Hi Anonymous
You can try this measure. But the section in SWITCH function is still hard coding.
Result = VAR _table = SUMMARIZE ( 'Table', 'Table'[GroupID], 'Table'[CustType], 'Table'[Group_CustType_Concat], "Sum_Of_Amount", SUM ( 'Table'[Amount] ) ) VAR _table2 = ADDCOLUMNS ( _table, "Amount*Parameter", [Sum_Of_Amount] * SWITCH ( [Group_CustType_Concat], "1Intermediate", [Intermediate G1 Value], "2Intermediate", [Intermediate G2 Value], "1Regular", [Regular G1 Value], "2Regular", [Regular G2 Value], "1Rare", [Rare G1 Value], "2Rare", [Rare G2 Value] ) ) RETURN SUMX ( _table2, [Amount*Parameter] )I use a table visual in my sample. For a line chart, you can put CustType on Axis or Legend to check the result.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
v-jingzhang
Community Support
4 years agoHi Anonymous
You can try this measure. But the section in SWITCH function is still hard coding.
Result =
VAR _table =
SUMMARIZE (
'Table',
'Table'[GroupID],
'Table'[CustType],
'Table'[Group_CustType_Concat],
"Sum_Of_Amount", SUM ( 'Table'[Amount] )
)
VAR _table2 =
ADDCOLUMNS (
_table,
"Amount*Parameter",
[Sum_Of_Amount]
* SWITCH (
[Group_CustType_Concat],
"1Intermediate", [Intermediate G1 Value],
"2Intermediate", [Intermediate G2 Value],
"1Regular", [Regular G1 Value],
"2Regular", [Regular G2 Value],
"1Rare", [Rare G1 Value],
"2Rare", [Rare G2 Value]
)
)
RETURN
SUMX ( _table2, [Amount*Parameter] )
I use a table visual in my sample. For a line chart, you can put CustType on Axis or Legend to check the result.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.