Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MohitPowerBI
Frequent Visitor

Filter an entire table based on What If Parameter and Logged In User Name

Hello,

 

I am trying to filter the data based on logged in user and a cutom filter(slicer) which I created using What If Parameter of type Whole Number. I used below DAX to convert Whole Number Parameter to a string type slicer ( for end users)

 

Projects = SWITCH(TRUE(), Projects[Projects Value] = 1, "My Projects Only", Projects[Projects Value] = 2, "All Projects")

Projects_WhatIf.png

Now, I want to use this slicer to filter the data from Project table. 

 

If User selects 'My Projects Only', It should display Projects where 'PROJECT_MANAGER = Logged in User' , otherwise it should display all rows.

 

Project Table.png

Any ideas on how to achieve this in Power BI/DAX are much appreciated!

 

Thanks,

Mohit

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Project Visible :=
var __selection = SELECTEDVALUE( Projects[Project Value] )
var __currentUser = USERNAME()
var __oneProjectVisible = HASONEVALUE( TheProjects[Project_ID] )
-- ManagerUserName must be in the format of __currentUser
var __currentProjManager = VALUES( TheProjects[ManagerUserName] )
return
	if( __oneProjectVisible,
			
		if(
			__selection = 1, -- my proj only
			__currentProjManager = __currentUser,
			TRUE() -- show all rows
		),
		
		-- don't show anything if many projects
		-- are visible in the current context.
		FALSE()
	)

-- The table with projects, TheProjects, must
-- have a column that stores your managers'
-- domain-name\user-name identifiers.
-- You can filter your table in a visual using
-- the above measure. If TRUE(), show the row,
-- if FALSE() hide.

Best

Darek

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Project Visible :=
var __selection = SELECTEDVALUE( Projects[Project Value] )
var __currentUser = USERNAME()
var __oneProjectVisible = HASONEVALUE( TheProjects[Project_ID] )
-- ManagerUserName must be in the format of __currentUser
var __currentProjManager = VALUES( TheProjects[ManagerUserName] )
return
	if( __oneProjectVisible,
			
		if(
			__selection = 1, -- my proj only
			__currentProjManager = __currentUser,
			TRUE() -- show all rows
		),
		
		-- don't show anything if many projects
		-- are visible in the current context.
		FALSE()
	)

-- The table with projects, TheProjects, must
-- have a column that stores your managers'
-- domain-name\user-name identifiers.
-- You can filter your table in a visual using
-- the above measure. If TRUE(), show the row,
-- if FALSE() hide.

Best

Darek

Thank you Darek, it worked like a charm 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors