How to stop Power BI from removing duplicates when creating a data.frame using R script visual?

powerbi, r

Solution

Add an index/unique column to the visual. In other words, create a column in the table your date_key is in and set it equal to this (and then add the column to the R visual):

index = 
RANKX (
    FILTER (
        yourTable,
        EARLIER ( yourTable[CC] ) = yourTable[CC]
            && EARLIER ( yourTable[Type] ) = yourTable[Type]
            && yourTable[Cluster] = yourTable[Cluster]
            && EARLIER ( yourTable[Status] ) = yourTable[Status]
    ),
    yourTable[Avg-Position],
    ,
    ASC
)

As seen here: https://community.powerbi.com/t5/Desktop/Add-calculated-index-column-by-DAX/td-p/72448

Problem

Problem: I am trying to keep all records when creating a data frame using R in Power BI. If I enter the data into the R script visual it automatically applies unique() removing, duplicate records. I am working with data in long format, so I do not want this to happen. Question: How do you stop power BI from applying unique() when generating a data frame in R script visual? Example of code generated by Power BI ``` #Create dataframe #dataset <- data.frame(date_key) #Remove duplicated rows #dataset <- unique(dataset) ```

Original source