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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
rlu
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
rlu
Frequent Visitor

any update?

dax
Community Support
Community Support

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

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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors