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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
che1569250
Regular Visitor

Is it possible for this R loop to be converted to DAX?

Hi all, I have an R loop that I'm running at Power Query level in Power BI. I'd like to be able to move this into DAX so I can use a parameter in my report, that the report user can add in themselves.

This is the R script:

 

 

 

tot <- dataset$Total
m_start <- dataset$Date
m_days <- dataset$DaysinMonth
s_lb <- dataset$Oustanding #Fixed value I want to use as a parameter instead
s_lb <- s_lb[1]

i <- 1
v1 <- c()
v2 <- c()
while (i<=length(dataset$Total)){
    int <- ((s_lb*0.12)/365)*m_days[i]
    s_lb <- s_lb - tot[i] + int
    v1 <- c(v1,s_lb)
    v2 <- c(v2,int)
    i <- i + 1
}

output <- data.frame(m_start,tot,v2,v1)

 

 

 

This produces two new columns using v1 and v2. Currently I have added the parameter as a column with the same value for each row. Ideally this would just be the parameter value the report user can input.
Any input on this would be great, I'm not entirely sure it is possible, but loops in DAX I find extremely difficult to get my head around.

2 REPLIES 2
v-diye-msft
Community Support
Community Support

Hi @che1569250 

 

Sorry I'm not quite understand the calculation logic, could you plz consider providing your dummy pbix  that would be helpful for us to investigate it further. 

You can upload it to the onedrive for business and share the link here. please don't forget to disclose the expected results and remove the confidential info.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Hi, this is a link to a Power BI file with a table of how the data starts and another table with how I want the data to look at the end. I need this to be done via DAX as I want to be able to enter "outstanding balance" as a parameter so it can change and update. 
Also, this a link to a file to show how I can do it in Excel.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors