{"id":1528,"date":"2025-09-24T16:37:14","date_gmt":"2025-09-24T14:37:14","guid":{"rendered":"https:\/\/www.flip-design.de\/?p=1528"},"modified":"2025-09-24T16:37:14","modified_gmt":"2025-09-24T14:37:14","slug":"power-bi-user-defined-functions-dax-udfs","status":"publish","type":"post","link":"https:\/\/www.flip-design.de\/?p=1528","title":{"rendered":"Power BI User Defined Functions &#8211; <strong>DAX UDFs<\/strong>"},"content":{"rendered":"\n<p>I was very happy that this feature finally went into public preview! I enjoy developing with UDFs, especially in the SQL Server environment. I had already needed this feature for the following blog post:<br>https:\/\/www.flip-design.de\/?p=1447<\/p>\n\n\n\n<p>This follows the concept of passing multiple values \u200b\u200bseparated by a delimiter. So, similar to a one-dimensional array.<\/p>\n\n\n\n<p>So I set about implementing this feature within Power BI.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-21.png\"><img decoding=\"async\" loading=\"lazy\" width=\"940\" height=\"505\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-21.png\" alt=\"\" class=\"wp-image-1529\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-21.png 940w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-21-300x161.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-21-768x413.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/a><\/figure>\n\n\n\n<p>Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DEFINE\r\n    FUNCTION SplitByIndex = (\r\n        inputText : STRING,\r\n        position  : INT64\r\n    ) =>\r\n        VAR Parts =\r\n            SELECTCOLUMNS (\r\n                ADDCOLUMNS (\r\n                    GENERATESERIES ( 1, PATHLENGTH ( inputText ) ),\r\n                    \"Item\", PATHITEM ( inputText, &#91;Value], TEXT )\r\n                ),\r\n                \"Index\", &#91;Value],\r\n                \"Part\",  &#91;Item]\r\n            )\r\n        RETURN\r\n            MAXX ( FILTER ( Parts, &#91;Index] = position ), &#91;Part] )\r\n<\/code><\/pre>\n\n\n\n<p>It&#8217;s important to note that, as we highlighted under 1, an error sometimes occurs during creation. The function should still be created, so this message can be ignored. To subsequently change this function, you should switch to the TMDL mask, where you won&#8217;t receive these errors.<\/p>\n\n\n\n<p>As a next step, I developed a measure that calls this function. Instead of manually passing the list, in a real-world scenario, at least as I wrote it, you would access the variable CUSTOMDATA(), which then returns the corresponding list. This way, you only create one measure for each segment, which you can then use in the DAX code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-22.png\"><img decoding=\"async\" loading=\"lazy\" width=\"940\" height=\"348\" src=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-22.png\" alt=\"\" class=\"wp-image-1530\" srcset=\"https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-22.png 940w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-22-300x111.png 300w, https:\/\/www.flip-design.de\/wp-content\/uploads\/2025\/09\/image-22-768x284.png 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/a><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>Part2_Measure = \r\n    SplitByIndex ( \"w|u|i|p\", 2 )<\/code><\/pre>\n\n\n\n<p>Further information can also be found here:<br>https:\/\/powerbi.microsoft.com\/en-us\/blog\/dax-udfs-preview-code-once-reuse-everywhere\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was very happy that this feature finally went into public preview! I enjoy developing with UDFs, especially in the SQL Server environment. I had already needed this feature for the following blog post:https:\/\/www.flip-design.de\/?p=1447 This follows the concept of passing &hellip; <a href=\"https:\/\/www.flip-design.de\/?p=1528\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1528"}],"collection":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1528"}],"version-history":[{"count":1,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flip-design.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}