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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.