Forum Discussion
WSwanson
8 years agoFrequent Visitor
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...
- 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 SourceBest Regards,
Dale
v-jiascu-msft
8 years agoMicrosoft Employee
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
SourceBest Regards,
Dale