Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
I am new to Power BI and trying to figure out how to do filtering based on one of the current user details.
Can someone please help me with the code for this.
I am trying to filter the main table(User Tasks) to show the items only that are related to current logged in user lab.
As in the screenshot below. I am able to create a measure(using USERPRINCIPALNAME functions) called Current User Lab from the Contacts Table. This measure shows the Lab of the current logged in user.
I would like to show the items in the main table below(User Tasks) ONLY that are related to Current User Lab i.e., show only items which matches with any one of the TrimmedDeptTestResponsible OR TrimmedDeptProjLeader OR TrimmedDeptCreatedBy Screenshot below.
@dk_dk @Anonymous @Ritaf1983 @amitchandak @Ashish_Mathur
Solved! Go to Solution.
Hi @Sumanth327 ,
Sorry for being late! Back to work.
Assuming you already have a measure dedicated to getting Dept Code, we can change DAX to:
Measure =
VAR _Current_User_Lab = [Current User Lab]
VAR _Current_Dept_Code = [Dept Code]
RETURN
IF(
_Current_Dept_Code <> 2132,
IF(
MAX('Table'[TrimmedDeptCreatedBy]) = _Current_User_Lab || MAX('Table'[TrimmedDeptProjLeader]) = _Current_User_Lab || MAX('Table'[TrimmedDeptTestResponsible]) = _Current_User_Lab,
1,
0
),
1
)
Here I am defaulting to 2132 as a numeric type, if you are using a text type, please change it to “2132”.
The final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous , Thank you so much for the help.
Can you help me with this additional condition also which I got to know today. i.e.,
If the Dept Code measure is equal to 2132 then no filterings has to be applied i.e., show all the items without conditions you have suggested above.
If the Dept Code measure is not equal to 2132 then all the logic you have suggested has to be applied.
Hi @Sumanth327 ,
Sorry for being late! Back to work.
Assuming you already have a measure dedicated to getting Dept Code, we can change DAX to:
Measure =
VAR _Current_User_Lab = [Current User Lab]
VAR _Current_Dept_Code = [Dept Code]
RETURN
IF(
_Current_Dept_Code <> 2132,
IF(
MAX('Table'[TrimmedDeptCreatedBy]) = _Current_User_Lab || MAX('Table'[TrimmedDeptProjLeader]) = _Current_User_Lab || MAX('Table'[TrimmedDeptTestResponsible]) = _Current_User_Lab,
1,
0
),
1
)
Here I am defaulting to 2132 as a numeric type, if you are using a text type, please change it to “2132”.
The final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Sumanth327 ,
You mentioned that you've managed to get Current User Lab via measure, so I'll use Slicer instead in my tests next. Here is my sample data:
Use this DAX to create a measure:
Measure =
VAR _Current_User_Lab = [Current User Lab]
RETURN
IF(
MAX('Table'[TrimmedDeptCreatedBy]) = _Current_User_Lab || MAX('Table'[TrimmedDeptProjLeader]) = _Current_User_Lab || MAX('Table'[TrimmedDeptTestResponsible]) = _Current_User_Lab,
1,
0
)
Set up the filter as shown below:
Drag the measure to the position indicated by the arrow:
Set the measure = 1 and Apply filter:
The final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
84 | |
77 | |
75 | |
43 | |
36 |
User | Count |
---|---|
109 | |
56 | |
52 | |
45 | |
43 |