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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

[need help] Error occurs when creating Sankey diagram by R script

Hi Team,

I did data transform by creating a new table with DAX, and the format of new table is sankey format: Source, Target, Occurs(Please refer to below table1)

Table1:

sankeytable.jpg

Then I trying to create sankey diagram with R visulization, here is the script:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
 
dataset <- data.frame(Source, Target, Occurs)
dataset <- unique(dataset)
library(networkD3)
dataset$Source = as.character(dataset$Source)
dataset$Target = as.character(dataset$Target)
Sankeylinks<-dataset
Sankeynodes<-data.frame(name=unique(c(Sankeylinks$Source,Sankeylinks$Target)))
Sankeynodes$index<-0: (nrow(Sankeynodes) - 1)
Sankeylinks<-merge(Sankeylinks,Sankeynodes,by.x="Source",by.y="name")
Sankeylinks<-merge(Sankeylinks,Sankeynodes,by.x="Target",by.y="name")
Sankeydata<-Sankeylinks[,c(4,5,3)];
names(Sankeydata)<-c("Source","Target","Occurs")
Sankeyname<-Sankeynodes[,1,drop=FALSE]
# draw sankey network
sankeyNetwork(Links=Sankeydata,Nodes=Sankeyname,Source="Source",Target="Target",Value="Occurs",NodeId="name",fontsize=8,nodeWidth=20)
But there is error occured.
error.jpg
 
what is the issue with my script?
1 REPLY 1
v-evelk
Microsoft Employee
Microsoft Employee

Hi,

 

The error on your picture says that field name is unavailable.

Please check that you correctly typed all your fileds names.

Also, pay attention please that using fileds must be added to "Values" bucket to be available in a script regarding this article.

 

Kind Regards,

 

Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
pbicvsupport@microsoft.com

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors