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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

transforming line context into measure context

Hey guys!

I need a conditional column to have a measurement context, because I'm using it as a filter. Below I put some images and codes

 

Conditional column result:

 

conditional column = 
var indice = CALCULATE(sum('base'[metric1]) / sum('base'[metric2]),  ALLEXCEPT( 'base',
        'base'[category], 
        'base'[description], 
        'base'[key_values_ogn], 
        'base'[name], 
        'base'[origem], 
        'base'[sub_category], 
        'base'[type], 
        'base'[type_1],
        'base'[date]))
var result = 
IF(indice <0.0021, "Low",
    IF(indice >= 0.0021 && indice <0.0051, "Medium",
        IF(indice >= 0.0051, "High",
            "Others")))
return result

 

ahsilva__0-1619444996047.png

 

Measure result:

 

conditional column = 
var indice = CALCULATE(sum('base'[metric1]) / sum('base'[metric2]))
var result = 
IF(indice <0.0021, "Low",
    IF(indice >= 0.0021 && indice <0.0051, "Medium",
        IF(indice >= 0.0051, "High",
            "Others")))
return result

 

ahsilva__1-1619445087007.png

 

I need the same behavior of the measurement in the column to be able to use it as a filter, can you help me, please?

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

When you refer that you need to have the same behaviour on the column has you have in the measure do you mean you want the calculation to be dinamic based on context of the table but being abble to use it in a slicer?

 

If you want to use the values of the measure in a slicer create  an unrelated table with results of the measure:

 

Option
Low
Medium
High
Low

 

Now create the following measure:

Filtering = IF([Measure] in VALUES('Options'[Option]), 1)

Now add this measure to the filter has a filtering and choose all values thar aren't blank final result below and in attach file:

MFelix_0-1619446486788.pngMFelix_1-1619446500321.png

another thing is that instead of using nested IF you should use switch syntax:

 

conditional column =
VAR indice =
    CALCULATE ( SUM ( 'base'[metric1] ) / SUM ( 'base'[metric2] ) )
VAR result =
    SWITCH (
        TRUE (),
        indice < 0.0021, "Low",
        indice >= 0.0021
            && indice < 0.0051, "Medium",
        indice >= 0.0051, "High",
        "Others"
    )
RETURN
    result

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @Anonymous ,

 

When you refer that you need to have the same behaviour on the column has you have in the measure do you mean you want the calculation to be dinamic based on context of the table but being abble to use it in a slicer?

 

If you want to use the values of the measure in a slicer create  an unrelated table with results of the measure:

 

Option
Low
Medium
High
Low

 

Now create the following measure:

Filtering = IF([Measure] in VALUES('Options'[Option]), 1)

Now add this measure to the filter has a filtering and choose all values thar aren't blank final result below and in attach file:

MFelix_0-1619446486788.pngMFelix_1-1619446500321.png

another thing is that instead of using nested IF you should use switch syntax:

 

conditional column =
VAR indice =
    CALCULATE ( SUM ( 'base'[metric1] ) / SUM ( 'base'[metric2] ) )
VAR result =
    SWITCH (
        TRUE (),
        indice < 0.0021, "Low",
        indice >= 0.0021
            && indice < 0.0051, "Medium",
        indice >= 0.0051, "High",
        "Others"
    )
RETURN
    result

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hey @MFelix !

This is exactly what i needed.

 

Thank you for helping me! 

 

Regards

Alex Silva

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors