Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
aruljothi
Frequent Visitor

For Next Function in PowerBI

Hello guys, how to do this Excel VBA equivalent in PowerBI. 

 

Function cust(mser, rratio)
Sum = 0
For n = 0 To mser - 1
Sum = Sum + rratio ^ n / FACT(n)
Next n
Sum = Sum + rratio ^ mser / FACT(mser) / (1 - rratio / mser)
cust = 1 / Sum
End Function

 

I am trying to do a some interactive model in which above function will be used as a measure. User will set the parameters and certain calculation will be done based on the user input. following is the screenshot. I am trying to do a calculation for "cust" using the function above

 

model.png

 

Pls help....

4 REPLIES 4
Anonymous
Not applicable

It looks like your function is describing a factorial function.  If n =5, you want the function to return 120 (1 * 2 * 3 * 4 * 5).

 

Use the DAX function FACT().

 

Documention is available here

Thanks you Chris, I understand what you mean, I just wrote it as an example. I want a finction to do some thing similar to that, for an example another function will be like this.... 

 

Function cust(mser, rratio)
Sum = 0
For n = 0 To mser - 1
Sum = Sum + rratio ^ n / FACT(n)
Next n
Sum = Sum + rratio ^ mser / FACT(mser) / (1 - rratio / mser)
cust = 1 / Sum
End Function

 

you can think some solution for this?

Anonymous
Not applicable

You can use GENERATESERIES() to create a table of values, and then pass that into ADDCOLUMNS() to create some additional columns that could access those values and perform some sort of calculation on them.

 

Finally passing this table into a SUMX() or AVERAGEX() would convert the table into a single scalar value.

 

I think your request is still a little vague, are you able to share what your use case is?

 

DAX doesn't really support recursive functions.  M can do a little recursion, but it involves List.Generate(), which is involved.

Thanks Again, I am trying to do a some dynamic model, where user will set the parameters and certain calculation will be done based on the user input. following is the screenshot. I am trying to do a calculation for "cust" using the function above

 

Function cust(mser, rratio) Sum = 0 For n = 0 To mser - 1 Sum = Sum + rratio ^ n / FACT(n) Next n Sum = Sum + rratio ^ mser / FACT(mser) / (1 - rratio / mser) cust = 1 / Sum End FunctionFunction cust(mser, rratio) Sum = 0 For n = 0 To mser - 1 Sum = Sum + rratio ^ n / FACT(n) Next n Sum = Sum + rratio ^ mser / FACT(mser) / (1 - rratio / mser) cust = 1 / Sum End Function

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.