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
shas
Frequent Visitor

New Column creation based on filtered Measure

Hi,

I have the sample data as below.

categoryrangeyearPriceVariance
Category1120201000-200
Category122020120050
Category2320211600250
Category2420221700-150
Category2520211800100
Category3120222000200
Category3220232500-300
Category332022600-50
Category3420218000250
Category3520209000800

 

I have created a measure which (price+Variance)/price. using Calculate function filtered this measure to  category=category1 and range=1 which gave me a value 0.8 now I need to use this value  from this measure and multiple to price column and create a new column but when i do that the value is displayed in 1st row which has the filters of measure and all other rows are empty. I need this operation to be applied to every row in the new column.

 

Thank you!

1 ACCEPTED SOLUTION
Daniel29195
Super User
Super User

@shas 

output : 

Daniel29195_0-1706744333995.png

 

if i understood correcrtly, you created a measure  = (price+Variance)/price with calculate to filter on category 1 and range 1 .

then you are using this measure in a calculated column to multiply it with price .

 

if that so, 

let me help you :

 

create a calculated column as follow : 

 

 

Column = 
var datasource= 
FILTER(
    'Table (2)',
    'Table (2)'[category] = "Category1" &&  'Table (2)'[range] = 1
)
var price =SELECTCOLUMNS(datasource, 'Table (2)'[Price])
var vriance = SELECTCOLUMNS(datasource, 'Table (2)'[Variance])
var res =  (price+ vriance)/price

return res * 'Table (2)'[Price]

  

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

View solution in original post

4 REPLIES 4
shas
Frequent Visitor

Hi 

This works fine for the scenario i have described but if i want to use the res* price for range1 and calculate another res for range2 and use that as res for all the range2 and so on for other ranges is that possible.

@shas 

yes. 

you calculate for range2 

 

then you return 

switch(
true() , 

tbl_name[range] = 1 ,   res1 , 

tbl_name[range] = 2 , res2 , 

 

....

 

 

 

 

 

Daniel29195
Super User
Super User

@shas 

output : 

Daniel29195_0-1706744333995.png

 

if i understood correcrtly, you created a measure  = (price+Variance)/price with calculate to filter on category 1 and range 1 .

then you are using this measure in a calculated column to multiply it with price .

 

if that so, 

let me help you :

 

create a calculated column as follow : 

 

 

Column = 
var datasource= 
FILTER(
    'Table (2)',
    'Table (2)'[category] = "Category1" &&  'Table (2)'[range] = 1
)
var price =SELECTCOLUMNS(datasource, 'Table (2)'[Price])
var vriance = SELECTCOLUMNS(datasource, 'Table (2)'[Variance])
var res =  (price+ vriance)/price

return res * 'Table (2)'[Price]

  

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Hi

This solve the problem of showing the value in all rows but the filtering does not work it calculates the res value using all the rows in the table.

 

Thank you!

 

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.