Skip to main content
Microsoft Idea

Power BI

Under Review

Custom (Reusable) DAX Function

Vote (667) Share
Omaer Khan's profile image

Omaer Khan on 01 Mar 2017 02:06:50

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.

Comments (57)
Omaer Khan's profile image Profile Picture

Robert Mela on 06 Jul 2020 00:10:59

RE: Custom (Reusable) DAX Function

Agree, much time can be saved from creating your own functions with parameter passing.

DAX is great, make it greater, thanks.

Omaer Khan's profile image Profile Picture

jeffrey Weir on 06 Jul 2020 00:09:38

RE: Custom (Reusable) DAX Function

Is this something that Calculation Groups would solve (if introduced into Power BI?) https://www.sqlbi.com/articles/introducing-calculation-groups/

Omaer Khan's profile image Profile Picture

Ben Wefers on 06 Jul 2020 00:09:35

RE: Custom (Reusable) DAX Function

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.

Omaer Khan's profile image Profile Picture

Power BI User on 06 Jul 2020 00:05:43

RE: Custom (Reusable) DAX Function

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.

Omaer Khan's profile image Profile Picture

Power BI User on 06 Jul 2020 00:05:29

RE: Custom (Reusable) DAX Function

Please add User defined functions to Power BI

Omaer Khan's profile image Profile Picture

Jose on 06 Jul 2020 00:05:03

RE: Custom (Reusable) DAX Function

Yes, please add to Power BI.

Omaer Khan's profile image Profile Picture

Kevin on 06 Jul 2020 00:03:13

RE: Custom (Reusable) DAX Function

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.

Omaer Khan's profile image Profile Picture

Juliusz Gonera on 06 Jul 2020 00:01:05

RE: Custom (Reusable) DAX Function

'+1. I have a spreadsheet with only tens of custom measures and managing them all is already a nighmare.

Omaer Khan's profile image Profile Picture

Alex Eisenhart on 06 Jul 2020 00:00:37

RE: Custom (Reusable) DAX Function

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.

Omaer Khan's profile image Profile Picture

Power BI User on 05 Jul 2020 23:59:30

RE: Custom (Reusable) DAX Function

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.

Merged Idea (1)