cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rlu Frequent Visitor
Frequent Visitor

zoo's na.locf function not filling fields with R script in Power Query Editor

I'm trying to use the zoo package's na.locf() function to fill missing values in adjacent rows. It works when I run it in RStudio, but it does not work in PowerBI. Here's an abridged version of the R code:

 

library(dplyr)
library(zoo)
library(lubridate)

fillGuids <- clean %>%
    arrange(User, Serial, desc(ClientTime_clean), MetaGuid, desc(Action)) %>%
    group_by(User,Serial,date(ClientTime_clean)) %>%
    mutate(MetaGuid_filled = zoo::na.locf(MetaGuid, na.rm=FALSE)) %>% 
    ungroup() %>% #fill all missing MetaGuids that come after first log by User/Serial/date

 

This is the desired output for the MetaGuid_filled field, derived from the MetaGuid field. However, the output from PowerBI is just what's in MetaGuid. No errors are thrown, but this is not the expected behavior of na.locf. Not to mention the exact same code works when using my RStudio IDE.

 

MetaGuid_filledMetaGuidUserSerialActionClientTime_clean
A123456A123456A1ViewDocument10/22/2019
A123456A123456A1ViewDocument10/22/2019
A123456A123456A1ViewDocument10/22/2019
A123456A123456A1ViewDocument10/22/2019
A123456 A1ExecuteSearch10/22/2019
B987654B987654A1ViewDocument10/22/2019
B987654B987654A1ViewDocument10/22/2019
B987654 A1ExecuteSearch10/22/2019
3 REPLIES 3
Community Support Team
Community Support Team

Re: zoo's na.locf function not filling fields with R script in Power Query Editor

Hi rlu,

I am not familiar on R script, I will discuss this with outhers and try to reproduce this in my environment. I will inform you as soon as I get it 

In addition, if you want to fill it up, why not use M code to achieve this goal

You could replace empty cell by null, then click Fill->down

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MjYxNVPSUXIEYkMgDstMLXfJTy7NTc0rAQkZ6BsZ6RsZGFoqxeoMPvVICl0rUpNLS1KDUxOLkjMwVTpZWpibmZoQbTKp6ol0SSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [MetaGuid = _t, User = _t, Serial = _t, Action = _t, ClientTime_clean = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"MetaGuid"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"MetaGuid"})
in
    #"Filled Down"

441.PNG

Thanks for your understanding and support.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

rlu Frequent Visitor
Frequent Visitor

Re: zoo's na.locf function not filling fields with R script in Power Query Editor

Thanks for your response Zoe. I'm looking to maintain just one data munging pipeline as I use the same R script for offline analysis as well and wanted to use the same script to turn on a PowerBI dashboard to monitor metrics. Thus, M code will not be beneficial for me.

Highlighted
rlu Frequent Visitor
Frequent Visitor

Re: zoo's na.locf function not filling fields with R script in Power Query Editor

any update?

Helpful resources

Announcements
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,944)