Skip to main content

Power BI

Needs Votes

Custom (Reusable) DAX Function

Vote (303) 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 (30)
Omaer Khan's profile image Profile Picture

eb65a39d 1854-45bb-b239-8d77f28c7263 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

94ed9788 abc6-4693-8d61-7c264bfb9a17 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

Omaer Khan's profile image Profile Picture

cd63d6d0 a73f-4c54-92ce-253d3daaa75f on 05 Jul 2020 23:33:53

RE: Custom (Reusable) DAX Function

Copy-paste waste my time and it's hard to maintain a bunch of duplicate dax code.

Omaer Khan's profile image Profile Picture

a305a2cc 8bc7-4569-81f6-0364c8b427b3 on 05 Jul 2020 23:30:25

RE: Custom (Reusable) DAX Function

Code reuse is basic

Omaer Khan's profile image Profile Picture

d0648e4a 850b-4beb-95e2-c57776a4d46e on 05 Jul 2020 23:30:24

RE: Custom (Reusable) DAX Function

Yes that is required

Omaer Khan's profile image Profile Picture

ff238841 3458-45b7-879e-063ae9abbe4c on 05 Jul 2020 23:29:30

RE: Custom (Reusable) DAX Function

Somewhat flabbergasted that this doesn't appear to be supported.

Omaer Khan's profile image Profile Picture

eb845b7b 66b7-4610-b1d4-f31cf081dfd3 on 05 Jul 2020 23:26:58

RE: Custom (Reusable) DAX Function

Agree !
basic and super powerful.

PBI TEAM - pls. add this

Omaer Khan's profile image Profile Picture

08565e15 0e1d-43ec-9c3f-613d02049f71 on 05 Jul 2020 23:05:33

RE: Custom (Reusable) DAX Function

UDF is a basic concept of any programming language

Omaer Khan's profile image Profile Picture

f3870a8b 643d-4dd5-946b-834f0e42c5ba on 05 Jul 2020 23:04:56

RE: Custom (Reusable) DAX Function

Yes, we absolutely need this.

Omaer Khan's profile image Profile Picture

f463f5ab 18b0-424e-9904-ce7987500427 on 05 Jul 2020 22:52:29

RE: Custom (Reusable) DAX Function

It seems a no-brainer to have this capability, and is so weird that it appears that it doesn't (I've been trying to find a way of doing it for a bit now!). If DAX could have UDFs, it would be possible to start to build a library of data analysis functions that could rival R for data science applications. But without this expandability, it is not in as competitive of a position.