Skip to main content

Power BI

Under Review

Custom (Reusable) DAX Function

Vote (718) 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 (59)
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.

Omaer Khan's profile image Profile Picture

Elena on 05 Jul 2020 23:57:45

RE: Custom (Reusable) DAX Function

It would be incredibly useful

Omaer Khan's profile image Profile Picture

Adam Estrada on 05 Jul 2020 23:51:51

RE: Custom (Reusable) DAX Function

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.

Omaer Khan's profile image Profile Picture

Lesze on 05 Jul 2020 23:49:44

RE: Custom (Reusable) DAX Function

I agree wholeheartedly.
Why recreate the wheel every time you need one

Omaer Khan's profile image Profile Picture

Wout O on 05 Jul 2020 23:45:43

RE: Custom (Reusable) DAX Function

Would be very useful and easier to do updates to a measurement (along with source control hopefully somewhere in the future)

Omaer Khan's profile image Profile Picture

ammannasm@gmail.com on 05 Jul 2020 23:45:07

RE: Custom (Reusable) DAX Function

Please update on this,

This will make power bi a power full tool.

need this ASAP

Omaer Khan's profile image Profile Picture

Jonathan on 05 Jul 2020 23:40:56

RE: Custom (Reusable) DAX Function

Any updates on this, Power BI Team? It's shocking that a product like this requires so much code duplication, it makes it so hard to maintain.

Omaer Khan's profile image Profile Picture

Roy Wells on 05 Jul 2020 23:34:47

RE: Custom (Reusable) DAX Function

Yes to this. Huge issue on large models with many similar complex measures

Omaer Khan's profile image Profile Picture

Power BI User on 05 Jul 2020 23:34:05

RE: Custom (Reusable) DAX Function

100% keen for this. Also would appreciate having a built-in solution for working time, was surprised to find that you have to write that yourself

Merged Idea (1)