Forum Discussion

WSwanson's avatar
WSwanson
Frequent Visitor
8 years ago
Solved

Restricting Query by Username DAX Command in Direct Query

We have a Direct Query dataset in which we are trying to limit a table specifically by the domain name of the user pulling the report. This is being done in the Advanced Editor screen in the Query Ed...
  • v-jiascu-msft's avatar
    8 years ago

    Hi WSwanson,

     

    USERNAME() is a DAX function. So you can't use it in the Query Editor that uses Power Query. Please vote on this idea. The workaround could be found here. I tested it with R code. It worked. You can try it like bellow.

    let
        RScript = R.Execute("output <- read.table(text=system2(""whoami"", stdout=TRUE))"),
        output = RScript{[Name="output"]}[Value],
    
        Source = Sql.Database("SqlServerName", "contosoretaildw", [Query="select * from DimCustomer where lastname = '&output&'"])
    in
        Source

    Best Regards,

    Dale