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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
elguestca1
Advocate I
Advocate I

Creating a measure with if condition to return value from the same column

Hello,

i was wondering is there a way to write a measure with a condition which refers to a column the result is needed from?

I think it may be difficult, so i will try to explain the situation.

In Power Apps we have a mapping environment. I wont go into mapping details, but the result we are having looks something like in the photo column A and B. 

elguestca1_0-1730290568496.png


I want to have a matrix table where we would be able drill down from first level to second. It means top level should be P.1,P.2,P.3 and their values should come from second level codes. 

The issue is that we dont have somekind of levels, we have codes and values in 2 columns, so i was wondering is there a way to create a measure if Code is P.1 it should return second level codes - P.1.1 (600) and P.1.2 (400). The result i want is also in the picture.

I would be able to create a new column, but i can only create a measure since the data is taken form Power BI model and can not be edited. 

Maybe it is a need to change the logic somehow in power apps mapping?

Thank you.




1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The below should work, but it will be slow and depending on the size of your data it might not be practicable

Aggregated Value =
VAR _CurrentCode =
    SELECTEDVALUE ( 'Table'[Code] )
VAR Result =
    IF (
        NOT ISBLANK ( _CurrentCode ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            CONTAINSSTRING ( 'Table'[Code], _CurrentCode )
        )
    )
RETURN
    Result

Ideally you would be able to build a parent child hierarchy which explicitly details which codes belong where, but that isn't always possible.

View solution in original post

2 REPLIES 2
elguestca1
Advocate I
Advocate I

Hello @johnt75,

it actually did the trick and works fine. Thank you!

johnt75
Super User
Super User

The below should work, but it will be slow and depending on the size of your data it might not be practicable

Aggregated Value =
VAR _CurrentCode =
    SELECTEDVALUE ( 'Table'[Code] )
VAR Result =
    IF (
        NOT ISBLANK ( _CurrentCode ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            CONTAINSSTRING ( 'Table'[Code], _CurrentCode )
        )
    )
RETURN
    Result

Ideally you would be able to build a parent child hierarchy which explicitly details which codes belong where, but that isn't always possible.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.