Forum Discussion
USERNAME() function DAX
v-haibl-msft First of all... thank you for answer...
Maybe this be possible with SSAS like explained this post
Somebody has to some else sugestion about this question?
Let’s try to use this function in measure as below. Not sure if it is the result you wanted.
Assuming we have a simple table like the following one.
We can create another new table which specific someone can only see the specified country.
We can create a measure with following formula to show the total sales according to the login user of Power BI service.
TotalSales =
VAR CountryForUser =
LOOKUPVALUE ( Table2[Country], Table2[Name], USERNAME () )
RETURN
(
IF (
CountryForUser <> BLANK (),
CALCULATE (
SUM ( Table1[Sales] ),
FILTER ( Table1, Table1[Country] = CountryForUser )
),
CALCULATE ( SUM ( Table1[Sales] ) )
)
)When I login to Service with the specified user in Table2, I can only see the total sales of China.
After I share the dashboard with another user, he can see the total sales of China and USA.
Best Regards,
Herbert
- Twister810 years ago
Helper II
v-haibl-msft tks for answer :smileyhappy:
I am trying do this solution...but i have a problem(In my test, your solution just work when I have the country and sales in the same component, table, if you log in with user that see China and create a table with just country, all coutries are listed, correct?), maybe this solution can be, create various functions DAX for each type column and more tables for combination .....what do you think?
for example, I have a dataset with country e sales by year, but i have inside the country some states, some companies, and I need show filters too. The user can see just some countries, some states and some companies:
Twiter8 can see, country USA, but some states like TX, NY, FL, and some companies like company A and company F......I am thinking that solution is:
Slicer
Country: State Company
USA TX ANY A
FL F
TotalSales = VAR StateForUser = LOOKUPVALUE ( Table2[State], Table2[Name], USERNAME () ) RETURN ( IF ( CountryForUser <> BLANK (), CALCULATE ( SUM ( Table1[Sales] ), FILTER ( Table1, Table1[Country] = StateForUser ) ), CALCULATE ( SUM ( Table1[Sales] ) ) ) )I guess the solution because, when I included a slicers, in your example, by state or company, its showing every states and company instead the just show state and company by country and user....
What do you think...?
- v-haibl-msft10 years ago
Microsoft Employee
If you want to let the login users only see specified country in Slicer, I don’t think it is possible. For fields of slicer, we need to put column into it. So when we login with Twister8, each country in the country column will be displayed but not only USA. We’re not able to filter the column like we did in above measure.
Best Regards,
Herbert