Custom (Reusable) DAX Function
I'd like to be able to create reusable functions in DAX, instead of using the same DAX code in multiple measures.
Example: I have some complicated DAX code, which calculates the no of working seconds between two date-times. This excludes holidays, weekends, and only counts seconds from the start of the work-day, to the end of the work-day.
I use this DAX code a lot, for many measures which need to be in "Working Time" (working hours/minutes).
I would love to not have to copy-paste a bunch of code into all of my measures, but to be able to create a reusable function instead.
I would love to have this function, too. Especially around passing arguments to these functions would be "very" helpful and would declutter a lot. Recent example, I had to do the same non-standard comparison calculation for 5 different product brands --> 5 new measures. one functions and 5 ways to define arguments would help.
Neil MacMullen commented
..tumbleweed... I genuinely wonder what the PowerBi team is working on sometimes when features like this get ignored for years.
Must have feature. Would be amazing to have the ability to define reusable functions in DAX.
Yeap..DAX seems very limited without this simple programming feature.
I want to cut the typing and make my code more readable
I have the exact same problem. I added several columns that calculate hours between 2 dates in DAX. Then was told, after the fact, it needed to exclude weekends and holidays. Now, I can either write a calculated formula in DAX and copy and paste the code everywhere, or I rewrite the whole thing in powerquery(M) and create a custom function and move ALL my columns, and obviously change my formulas from DAX to M. VERY FRUSTATING.
Robert Mela commented
Agree, much time can be saved from creating your own functions with parameter passing.
DAX is great, make it greater, thanks.
jeffrey Weir commented
Is this something that Calculation Groups would solve (if introduced into Power BI?) https://www.sqlbi.com/articles/introducing-calculation-groups/
Ben Wefers commented
Would be a great add. Currently having to use the exact same massive formula to generate a custom column for a dozen tables, and if I improve the formula in one of them, I have to re-copy and paste and localize it a dozen times.
Yes please. I currently have dozens of measures that are basically the same thing but pointed at different time windows (since they need to be directly compared). This would be a great add.
Please add User defined functions to Power BI
Yes, please add to Power BI.
This would be awesome, however, I suspect since no one from the Power BI team or Microsoft has commented, I figure this will never happen. I freaking need it now.
Juliusz Gonera commented
+1. I have a spreadsheet with only tens of custom measures and managing them all is already a nighmare.
Alex Eisenhart commented
This would be useful because I often need to do a linear interpolation in a measure with a What If Parameter, to shift between a min and max at a user-specified ratio. It's troublesome to repeat the linear interpolation formula and it would much easier if I could just create a Tween(min, max, ratio) function to leverage an abstract formula.
Would indeed be a big improvement for maintainbality and development time indeed. Im writing the same 2 formulas over and over, only difference are the ledger accounts that are being filtered.
It would be incredibly useful
Adam Estrada commented
Yes, please add to Power BI. This would end the long-winded DAX measures that are hard to read yet nonetheless critical for our company's reports.
Adding it to Excel's data model would be nice, too.
I agree wholeheartedly.
Why recreate the wheel every time you need one
Would be very useful and easier to do updates to a measurement (along with source control hopefully somewhere in the future)
Please update on this,
This will make power bi a power full tool.
need this ASAP