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)
- Merged Idea (1)
RE: Custom (Reusable) DAX Function
Custom functions would be so helpful for displaying number of seconds in mm:ss format.
RE: Custom (Reusable) DAX Function
Copy-pasting code is so 1990ies ... LOVE the feature in Power Query and Excel, would SO love to have a similar option in DAX. Thanks in advance ;-)
RE: Custom (Reusable) DAX Function
We create similar data structures using different filters for each customer group. Having the ability to create a user defined function would save time to copy and paste the same code again, and make the code easier to manage over time.
RE: Custom (Reusable) DAX Function
one of my use case is that i have a custom format string that i would apply to multiple measures
if i change this i have to edit all affected measures...
e.g.
var formatstr =
switch(MIN('Format'[Fmt])
,0,"#,##0"
,1,"#,##0.00"
)
return formatstr
RE: Custom (Reusable) DAX Function
I'd like to use a function to control number formatting. In Excel, the "Accounting" format will treat 0 and 0.01 differently when displaying with no decimal places. If it's a "true" zero, it will be displayed as a dash, but if it rounds to zero, it will be displayed as a 0. I need to replicate this in Power BI, but it applies to ALL THE NUMBERS, so I really need a function if I have any chance of doing this. Or you could just make Power BI formatting like Excel formatting.
RE: Custom (Reusable) DAX Function
Defining custom functions and sharing the function with other analysts across the organization would be invaluable for aligning KPI's across the enterprise.
RE: Custom (Reusable) DAX Function
This feature is a must. How can you write efficient code without user defined funtions?????
RE: Custom (Reusable) DAX Function
Yo MS Team - it's April 2023. Ping.
RE: Custom (Reusable) DAX Function
Unforgiveable that this has yet to be implemented, no wonder powerBI is not even more popular than it should be
RE: Custom (Reusable) DAX Function
IMHO, this is nothing but a Calculation Group that is applied to a measure by default at the measure level as opposed to being applied globally to all selected measures manually using a filter. That seems an easy addition. Calculation Groups are really just repetitive calculations that pass in an input measure using SELECTEDMEASURE. Despite the use case that everybody demonstrates, they are not just intended for time intelligence calculations.