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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Published report with R script using Apriori unexpected results

My code below displays a table with Apriori results. I'm able to see the rules, support, confidence, lift, and count in PowerBI Desktop. I sort by count which works in PowerBI Desktop. When I publish this report to the web, the column count is no longer displayed, and the script fails because of the sort. Any thoughts?

rules_by_count <- sort(basket_rules, by = "count")

 

#Main
library(Matrix)
library(arules)
library(plyr)
library(dplyr)
library(gridExtra)

itemList <- dataset
#itemList <- read.csv("ItemListAll.csv", header=TRUE, sep=",")

# Converting to a Matrix ####
itemList$const = TRUE

# Remove duplicates
dim(itemList)
orders <- unique(itemList)
dim(itemList)

# Need to reshape the matrix
itemList_max_prep <- reshape(data = itemList,
                           idvar = "SALESID",
                           timevar = "ITEMNAME",
                           direction = "wide")

# Drop the SALESID
itemList_matrix <- as.matrix(itemList_max_prep[,-1])

# Clean up the missing values to be FALSE
itemList_matrix[is.na(itemList_matrix)] <- FALSE

# Clean up names
colnames(itemList_matrix) <- gsub(x=colnames(itemList_matrix),
                               pattern="const\\.", replacement="")

itemList_trans <- as(itemList_matrix,"transactions")

#inspect(itemList_trans)

basket_rules <- apriori(itemList_trans, parameter = list(sup=0.00005,conf=0.75,target="rules", maxlen=3, maxtime=20))

rules_by_count <- sort(basket_rules, by = "count")
df_basket <- as(rules_by_count,"data.frame")
df_basket$support <- ceiling(df_basket$support * 100)
df_basket$confidence<- ceiling(df_basket$confidence * 100)
df_basket$lift<- round(df_basket$lift, digits = 2)
grid.table(head(df_basket, n = 5L))

I get this error. "Error in .local(x, decreasing, ...) : Unknown interest measure to sort by."

2 REPLIES 2
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

Could you get expected result without any error in Power BI service if removig the "Sort" in R script?

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

ah I should have tested that. It does work!

 

But why am I not able to see the 'Count' field on PowerBI service?

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.