Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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_filled | MetaGuid | User | Serial | Action | ClientTime_clean |
A123456 | A123456 | A | 1 | ViewDocument | 10/22/2019 |
A123456 | A123456 | A | 1 | ViewDocument | 10/22/2019 |
A123456 | A123456 | A | 1 | ViewDocument | 10/22/2019 |
A123456 | A123456 | A | 1 | ViewDocument | 10/22/2019 |
A123456 | A | 1 | ExecuteSearch | 10/22/2019 | |
B987654 | B987654 | A | 1 | ViewDocument | 10/22/2019 |
B987654 | B987654 | A | 1 | ViewDocument | 10/22/2019 |
B987654 | A | 1 | ExecuteSearch | 10/22/2019 |
any update?
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"
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.
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.