• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Friday, October 31, 2025
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Artificial Intelligence

A Actual-World Instance of Utilizing UDF in DAX

Admin by Admin
October 28, 2025
in Artificial Intelligence
0
Jakub zerdzicki qzw8l2xo5xw unsplash 1.jpg
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

READ ALSO

The Machine Studying Initiatives Employers Wish to See

Constructing a Guidelines Engine from First Rules


Introduction

The characteristic of user-defined features was launched as a primary preview model with the September 2025 launch.

This characteristic permits us to encapsulate enterprise logic in features, which may be referred to as like every other customary features.

On this piece, I’ll display use this characteristic with a real-world instance: calculating a forecast primarily based on inflation charges.

You will notice create a easy operate and deal with a extra complicated state of affairs.

Situation

Let’s think about an organization that desires to forecast its revenue with an inflation simulation.

They need to simulate how totally different inflation charges have an effect on their month-to-month revenue.

For simplicity, we ignore seasonality and use the final recognized month-to-month gross sales quantity to calculate the longer term revenue for the remainder of the yr.

The person should have the ability to set an inflation price and see how the numbers change.

Put together the information mannequin

Now, it relies on whether or not I begin with a brand new Energy BI file and cargo the information or add this performance to an current one.

The very first thing to do is to activate the Preview characteristic:

Determine 1 – Allow the Preview characteristic for user-defined features (Determine by the Writer)

You could be compelled to restart Energy BI Desktop after enabling it.

For an current Energy BI file, we have to set the right compatibility stage to create user-defined features (UDFs).

You possibly can both create a dummy operate, which is able to mechanically improve the compatibility stage, or use Tabular Editor to set it to at the least 1702:

Determine 2 – Use Tabular Editor to improve the compatibility stage of the database (Determine by the Writer)

You possibly can enter 1702 within the marked discipline and reserve it.

I’ll display create a easy UDF later on this piece.

Please go to the Microsoft documentation to study extra about creating a brand new UDF in Energy BI Desktop. You will discover the hyperlink within the references part on the finish of this text.

Including the speed choice

Because the person should have the ability to choose the inflation price, I add a parameter to the information mannequin:

Determine 3 – Add a parameter to the information mannequin for a numeric vary (Determine by the Writer)

After clicking on “Numeric vary” I fill out the shape:

Determine 4 – Organising the parameter for a proportion vary (Determine by the Writer)

Since I need to management the proportion, I set the vary to -0.02 to 0.05, which corresponds to -2% to five%.

After just a few seconds, the brand new slicer was mechanically added to the report web page.

Nevertheless it’s exhibiting solely the decimal numbers.
I have to change the quantity format to see percentages:

Determine 5 – Format the column of the parameter to a proportion (Determine by the Writer)

Now the slicer reveals the quantity as wanted:

Determine 6 – The slicer with the numbers as a proportion (Determine by the Writer)

Now it’s prepared to make use of.

Write the primary operate

First, let’s create a UDF to return the chosen Charge.

I want writing it in Tabular Editor, as a result of its DAX editor is far quicker than Energy BI Desktop.

However you’ll be able to create it within the DAX Question view in Energy BI Desktop as properly.

In Tabular Editor, I’m going to the Capabilities Node, right-click on it, and choose “New Person-Outlined operate”:

Determine 7 – Create a brand new UDF in Tabular Editor (Determine by the Writer)

Now I can set a reputation.

For this primary one, I set “ReturnRate”.

That is the code for the operate:

(
    Charge : DECIMAL VAL
)

=>
Charge

Throughout the brackets, I outline the Enter parameter.

After the => I can enter the DAX code for the operate.

On this case, I return the Enter parameter.

Now, I create a measure to make use of this Operate:

Get Inflation price = ReturnRate([Inflation rate Value])

The measure [Inflation rate Value] was created after I created the parameter to pick the Inflation price.

After I add a card and assign the brand new measure to it, I’ll see the chosen worth from the slicer:

Determine 8 – Two examples exhibiting that the Measure that calls the features returns the chosen inflation price (Determine by the Writer)

OK, that is an elementary operate, but it surely’s solely as an example the way it works.

Write the true operate

You might need observed the key phrase VAL within the parameter’s definition.

As you’ll be able to learn within the two articles under in additional element, now we have two modes to move parameters:

  • VAL: Cross the content material of the parameter as is.
  • EXPR: Cross the parameter as an expression, which can be utilized inside the operate like a normal Measure.

Within the following operate, I take advantage of each of them.

Right here is the entire code for the operate MonthlyInflation:

(
    Charge : DECIMAL VAL
    ,InputVal : EXPR
)
=>

VAR CurrentMonth =  MAX( 'Date'[MonthKey] )

VAR LastMonthWithData = CALCULATE(
                                LASTNONBLANK( 'Date'[MonthKey]
                                    , InputVal
                                )
                            , ALLEXCEPT( 'Date', 'Date'[Year] )
                        )
                        
VAR LastValueWithData = CALCULATE(InputVal
                                        ,ALLEXCEPT('Date', 'Date'[Year])
                                        ,'Date'[MonthKey] = LastMonthWithData
                                    )
                            
VAR MonthDiff = CurrentMonth - LastMonthWithData
VAR Consequence = IF(MonthDiff<=0
                    ,InputVal
                    ,(1 + ( Charge * MonthDiff ) ) * LastValueWithData
                    )

                                    
RETURN
    Consequence

The primary parameter of the operate is as earlier than.

The second parameter would be the expression of the enter measure.

Throughout the operate, I can use the parameter title to alter the filter context and different issues. I have to set the parameter as EXPR after I have to work on this manner inside the operate.

The operate performs the next steps:

  1. I get the very best MonthKey and retailer it within the variable CurrentMonth
    The content material is the month of the present filter context within the numerical type YYYYMM.
  2. I get the newest month of the present yr with a worth from the enter parameter (measure) and retailer it into the variable LastMonthWithData
  3. I subtract the present month from the newest month with knowledge to get the distinction. This would be the issue to calculate the inflation price. The result’s saved within the variable MonthDiff
  4. If MonthDiff is smaller than or equal to 0, then the filter context (Month) accommodates a worth from the enter variable
  5. If not, the filter context (Month) is sooner or later, and we are able to calculate the end result.

What I’m doing right here is to multiply the chosen inflation price by the variety of months because the final month with knowledge (LastMonthWithData).

Now, I can create a measure to dynamically calculate the forecast month-by-month primarily based on the chosen inflation price:

On-line Gross sales With Inflation =
    MonthlyInflation([Inflation rate Value], [Sum Online Sales])

That is the end result for an inflation price of three%:

Determine 9 – Results of utilizing the brand new UDF to calculate the income per 30 days primarily based on the chosen inflation price (Determine by the Writer)

The blue-marked months comprise precise knowledge, and the red-marked months are calculated primarily based on the chosen inflation price.

The wonder is that I can move any DAX expression to the measure that I need.

For instance, I can add On-line Gross sales with Retail Gross sales:

Determine 10 – Consequence with the Whole Gross sales when including up On-line and Retail Gross sales when calling the operate.

The measure for that is the next:

Whole Gross sales With Inflation =
    MonthlyInflation([Inflation rate Value], [Sum Online Sales] + [Sum Retail Sales])

Properly, that’s very straightforward.

I do know that the calculation may be very simplistic, however I used this instance to showcase what may be accomplished with UDFs.

What’s the purpose?

So, that’s the purpose with UDFs?

Many of the issues proven right here can be accomplished with Calculation teams.

Properly, that’s true.

However utilizing a UDF is far simpler than utilizing a Calculation Merchandise.

Furthermore, we are able to write model-independent UDFs and reuse them throughout a number of fashions.

Check out Prolong Energy BI with DAX Lib.

It is a rising assortment of model-independent UDFs containing logic that can be utilized in any knowledge mannequin.

Different differentiating factors between UDFs and Calculation Objects are:

  • UDFs can’t be grouped, however Calculation Objects may be grouped in Calculation Teams.
  • Calculation Objects don’t have parameters.
  • UDF may be straight referred to as like every other DAX operate.

Strive it out to study extra concerning the prospects of UDFs.

Conclusion

are an excellent addition to the toolset in Energy BI and Cloth.

I’m certain it should develop into more and more essential to know work with UDFs, as their potential will develop into extra obvious over time.

As we’re within the early phases of the introduction of this characteristic, we have to keep tuned to see what Microsoft will do subsequent to enhance it.

There are some restrictions on this characteristic. You discover them right here: Issues and limitations of DAX user-defined features.

There may be sufficient room for enchancment.

Let’s see what’s coming subsequent.

References

Right here, the Microsoft documentation for user-defined features: Utilizing DAX user-defined features (preview) – Energy BI | Microsoft Be taught.

That is the SQL BI article that explains the characteristic in nice element: Introducing user-defined features in DAX – SQLBI.

A group of free to make use of model-independent UDF: Prolong Energy BI with DAX Lib.

Like in my earlier articles, I take advantage of the Contoso pattern dataset. You possibly can obtain the ContosoRetailDW Dataset totally free from Microsoft right here.

The Contoso Information can be utilized freely below the MIT License, as described on this doc. I modified the dataset to shift the information to modern dates.

Tags: DAXRealWorldUDF

Related Posts

Zero 3.jpg
Artificial Intelligence

The Machine Studying Initiatives Employers Wish to See

October 31, 2025
Philosopher 1.jpg
Artificial Intelligence

Constructing a Guidelines Engine from First Rules

October 30, 2025
Image 409.jpg
Artificial Intelligence

4 Methods to Optimize Your LLM Prompts for Price, Latency and Efficiency

October 30, 2025
Gemini generated image jpjittjpjittjpji 1.jpg
Artificial Intelligence

Utilizing Claude Abilities with Neo4j | In the direction of Knowledge Science

October 29, 2025
Screenshot 2025 10 28 103945.jpg
Artificial Intelligence

Utilizing NumPy to Analyze My Day by day Habits (Sleep, Display Time & Temper)

October 28, 2025
1 6a4inwrtdvlxpqhuburybw.jpg
Artificial Intelligence

Deploy an OpenAI Agent Builder Chatbot to your Web site

October 27, 2025
Next Post
Image 369.jpg

Methods to Apply Highly effective AI Audio Fashions to Actual-World Functions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
Blog.png

XMN is accessible for buying and selling!

October 10, 2025
0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025
Holdinghands.png

What My GPT Stylist Taught Me About Prompting Higher

May 10, 2025
1da3lz S3h Cujupuolbtvw.png

Scaling Statistics: Incremental Customary Deviation in SQL with dbt | by Yuval Gorchover | Jan, 2025

January 2, 2025

EDITOR'S PICK

Clouds.jpg

Tessell Launches Exadata Integration for AI Multi-Cloud Oracle Workloads

October 15, 2025
1hrh2myh809upgo82ftpmeg Scaled.jpeg

Superior Time Intelligence in DAX with Efficiency in Thoughts

February 20, 2025
British columbia permanently bans crypto mining.jpeg

British Columbia Completely Bans Crypto Mining Energy Connections

October 24, 2025
Shutterstock Cloud Worry And Stress.jpg

Like people, ChatGPT would not reply effectively to tales of trauma • The Register

March 5, 2025

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • Let Speculation Break Your Python Code Earlier than Your Customers Do
  • The Machine Studying Initiatives Employers Wish to See
  • Coinbase CEO turns earnings name into surprising jackpot for prediction market merchants
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?