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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.