cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## If function cannot check inside a column

Hi,

pretty exicted for the first post in Power BI forums

i am trying to create a measure based on an if function which should check inside a column called "Class" which has 3 values (A, B, C), then return the value form a measure A if the class is A and return the value from Measure B if the Class is B... so what i am trying to write as a function is the following:

If(Classes[Class] = "A", [Coverage A KPI], If(Classes[Class] = "B", [Coverage B KPI], 0))

so my problem is the if function cannot see the column Class to check inside it... while i could do it easily on Excel but it does not work in Power BI

Regards,

1 ACCEPTED SOLUTION
Frequent Visitor

the error is gone but it does not give me the right results (it gives me all zeros!)

i re-tried the if function using measure inside the Classes table but also had to wrap it into a MAX function: and now it works perfectly

```Measure =
IF (
MAX ( Classes[Class] ) = "A", [Coverage A KPI],
IF ( MAX ( Classes[Class] ) = "B", [Coverage B KPI],
0 )
)```

really appreciate your time and help

Best Regards,

9 REPLIES 9
Super User

@mokhawaja

Value =
SWITCH (
Classes[Class],
Classes[Class] = "A", [Coverage A KPI],
Classes[Class] = "B", [Coverage B KPI],
Classes[Class] = "C", [Coverage C KPI],
0
)

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

Frequent Visitor

thank you @vanessafvg,

really appreciate your help... i used your suggested formula and it showed me the below error:

Regards

Super User

@mokhawajai think you have to create a new column not a new measure.

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

Frequent Visitor

Hi,

i tried the column... and now it says:

"Function 'SWITCH' does not support comparing values of type Text with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values."

Super User
try this ?

Value =
SWITCH (true(),
Classes[Class] = "A", [Coverage A KPI],
Classes[Class] = "B", [Coverage B KPI],
Classes[Class] = "C", [Coverage C KPI],
0
)

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

Frequent Visitor

the error is gone but it does not give me the right results (it gives me all zeros!)

i re-tried the if function using measure inside the Classes table but also had to wrap it into a MAX function: and now it works perfectly

```Measure =
IF (
MAX ( Classes[Class] ) = "A", [Coverage A KPI],
IF ( MAX ( Classes[Class] ) = "B", [Coverage B KPI],
0 )
)```

really appreciate your time and help

Best Regards,

Super User

@mokhawaja  well if it doesn't give you the correct result and it returns 0, something is wrong with the conditional statement, wouldn't it be better to try and resolve that?

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

Community Champion

MAX operates on numbers, not text. For text you could use FIRSTNONBLANK or LASTNONBLANK.

Proud to be a Super User!

Frequent Visitor

Hi..

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors