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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Using a Measure in SELECTCOLUMNS

Starting out with Power BI.

Struggling with what can be condensed down to the following.

Have a table called Adults.  Two columns Name and Age.

Have a table called Children, same structure as Adults.

Adults contains Bob, 50 and Sue, 35.

Children contains Andy,15 and Mary 10.

I have a parameter called pAge and a corresponding slicer.  I also have a measure mAge defined as part of the Adults table as 

mAge = pAge[pAge Value].
I want to merge the two tables and in doing so update the Age field for Bob's record to the value of the slicer.  Seems straing-forward enough.  The following code does work.
 
Family = SELECTCOLUMNS(union(Adults,'Children'),"Name",[Name],"Age",IF([Name]="Bob",75,[Age]))
 
But if try to reference the slicer, then the table s not updated correctly.
 
Family = SELECTCOLUMNS(union(Adults,'Children'),"Name",[Name],"Age",IF([Name]="Bob",'Adults'[mAge],[Age]))
 
I suspect it's something to do with context but it's pretty urgent that I get this or something that achieves the same result working.
 
Please help and thanks.
1 ACCEPTED SOLUTION

@Anonymous ,Press Alt+ enter in the formula box. There up ^ at the end, if you press that it will take the complete page

 

In case your issue is resolved, please mark the solution.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@Anonymous 

Can you share sample data and sample output.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for replying.

 

The tables are straight-forward.

Adults.  Two columns Name and Age.

Bob | 50

Sue | 35

Children. Two columns Name and Age.

Andy | 15

Mary | 10

 

The code creates the Family table correctly.

Bob | 50

Sue | 35

Andy | 15

Mary | 10

 

The issue is that Bob's age has not been updated with the value of the slicer defined.  As I say I suspect it's something to do with context but the example seems very trivial and I would have thought there would be some way of achieving the same result.

@Anonymous ,

I tried something like this.

Table = union(SELECTCOLUMNS(Adult,"Name",Adult[Name],"Age",if(Adult[Name]="Bob",75,Adult[Age])),Child)

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

OK, I can see you've swapped the UNION statement and the SELECTCOLUMNS round.

 

The main issue though is setting the age of Bob to be the value stored in the measure mAge.

 

So, to reiterate, if you create a 'What-If' parameter called pAge with a slider.  Create a measure called mAge and set it as follows

mAge = pAge[pAge Value].
 
What I want is for the combined table to show Bob with the age set in the slider.
 
For me, this is not working as Bob's age stays the same.
 
Thanks for your suggestions.

Check if this can help. I create a new measure in merged table

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

That looks like exactly what I am after.

 

One more simple question and it's a really simple one, I suspect.

 

I am using PBI Desktop.

 

If I select 'New Measure', for example, I get a single line area in which I can type my code.  How do I expand this area so that it is larger.  Simple question I know but I just can't see how to do this.

 

Many thanks for all your help, your solution will really help me.

@Anonymous ,Press Alt+ enter in the formula box. There up ^ at the end, if you press that it will take the complete page

 

In case your issue is resolved, please mark the solution.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.