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

90863221 eba9-438e-94c3-7f9b83213c9b 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

6cc06109 e584-4cba-b899-d7b7a7438684 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

972904f1 1eff-458b-aea2-1d57e9bc726c 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

98af88e0 4278-404d-84c9-fd70cafa559d 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

dd92451e def9-4661-95a7-240ad1c11fec 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

7cde8bb1 9f5c-4243-a999-5facec5e7f9f on 05 Jul 2020 23:57:45

RE: Custom (Reusable) DAX Function

It would be incredibly useful

Omaer Khan's profile image Profile Picture

54279af8 ad64-4c39-ba72-9d87c841276d 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

bda3a0d5 eeb2-4974-b90e-9c66c9ecd299 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

99c595dc 2946-4c56-a13b-71dcf5d54b8e 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

1b44c726 9759-4740-9765-6194a3d6d5a6 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