Forum Discussion
How to create reusable function
- Anonymous9 years ago
Eventually I created an M function following the tutorial here.
Anonymous,
As mentioned above, you may select Unpivot Columns in the Query Editor and use Matrix visual later. To invoke a custom function, you could create a new Blank Query and add code below to Advanced Editor.
https://msdn.microsoft.com/en-us/library/mt185361.aspx
let
QualitativeScore = (Score as number) => if Score < 10 then "Poor" else "Excellent"
in
QualitativeScoreunpivoting will not work because the columns are claculated columns. Invoking the custom function also works only on the edit query level thus no chance to do it if the score is a calculated column.
- v-chuncz-msft9 years ago
Community Support
Anonymous,
Instead of calculated column in DAX, you could add column in Query Editor as well.
- Anonymous9 years agoNot applicable
Yes you are right but DAX is much simpler than M when it comes to complex functions, even not so complex, simple if statements, or a SWITCH in M is alsmost impossible to do.
In my case the score that I want to calculate is a logarithm based on values of other columns. Anyways thanks for helping!
- v-chuncz-msft9 years ago
Community Support
Anonymous,
You may use the GENERATE Function similar to the CROSS APPLY condition in SQL.
Table = GENERATE ( X, UNION ( ROW ( "Attribute", "Score A", "Value", X[Score A] ), ROW ( "Attribute", "Score B", "Value", X[Score B] ) ) )