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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
sontt
Resolver I
Resolver I

Convert R script to powerbi function

Hi there

 

I try convert my string to sha256 with r-script function:

 

library(digest)
apikey <- "hello"
apimessage <-"world"
hash <- digest::hmac(apikey,apimessage, algo="sha256", serialize=F)

 

I found  similar thread here https://community.powerbi.com/t5/Desktop/Invoke-Function-writtein-in-R/td-p/87438 

but i still cant convert to powerbi function.

 

This is my file: https://drive.google.com/open?id=1wrZQgzeW8uvy7cNRWKPuiqICYhPfp6wc

Please help me convert it.

 

Thank you so much

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi sontt,

 

To achieve your requirement, please refer to R Script:

 

# 'dataset' holds the input data for this script

library(digest)

 

len <- length(dataset[[1]])

hash <- c()

for (i in 1:len) {

    hash <- append(hash, digest::hmac(dataset[i, 1],dataset[i, 2], algo="sha256", serialize=F))

}

dataset$hash <- hash

result <- dataset

 1.PNG

 

The result is like below and you can refer to PBIX file here:

https://www.dropbox.com/s/ykto8cwdrwg2gl8/For%20sontt.pbix?dl=0

 2.PNG

 

Best Regards,

Jimmy Tao

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi sontt,

 

To achieve your requirement, please refer to R Script:

 

# 'dataset' holds the input data for this script

library(digest)

 

len <- length(dataset[[1]])

hash <- c()

for (i in 1:len) {

    hash <- append(hash, digest::hmac(dataset[i, 1],dataset[i, 2], algo="sha256", serialize=F))

}

dataset$hash <- hash

result <- dataset

 1.PNG

 

The result is like below and you can refer to PBIX file here:

https://www.dropbox.com/s/ykto8cwdrwg2gl8/For%20sontt.pbix?dl=0

 2.PNG

 

Best Regards,

Jimmy Tao

Hi @v-yuta-msft

 

Thanks for your help. Thank u so much!!! Smiley Very Happy Smiley Very Happy Smiley Very Happy

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors