cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shikhavidyarthi
Frequent Visitor

# Expression error

I am creating a new custom column for a table with more than 30 columns. 

I am trying to create a new column with IF and ELSE Statement but getting the below error. Please let me know the correct syntax for this.

if [Criteria] = 1 then
(if [override_reason] = "KEEP" then Count[facility_id] else 0)/(count[facility_id]) else 0

 

 

shikhavidyarthi_0-1674229677254.png

 

1 ACCEPTED SOLUTION

 

Ah, ok.

You want to do this in DAX, not in Power Query. Create a DAX measure like this:

_Overr_ct_pct =
VAR __idCount =
COUNT(yourTable[Overr_ct])
VAR __total =
CALCULATE(
    COUNT(yourTable[Overr_ct]),
    REMOVEFILTERS(yourTable),
    VALUES(yourTable[id])
)
RETURN
IF(
    MAX(yourTable[Keep_num]) = 1,  // If [Keep_num] is a measure you can remove the MAX() and 'yourTable' bits
    DIVIDE(__idCount, __total, 0)
)

 

Select this new measure from the Fields list, go to the Measure Tools tab, change the format to Percent:

BA_Pete_0-1674543385466.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

5 REPLIES 5
shikhavidyarthi
Frequent Visitor

Hi,

 

I want the result as bottom screenshot.

shikhavidyarthi_0-1674507490403.png

 

 

Ah, ok.

You want to do this in DAX, not in Power Query. Create a DAX measure like this:

_Overr_ct_pct =
VAR __idCount =
COUNT(yourTable[Overr_ct])
VAR __total =
CALCULATE(
    COUNT(yourTable[Overr_ct]),
    REMOVEFILTERS(yourTable),
    VALUES(yourTable[id])
)
RETURN
IF(
    MAX(yourTable[Keep_num]) = 1,  // If [Keep_num] is a measure you can remove the MAX() and 'yourTable' bits
    DIVIDE(__idCount, __total, 0)
)

 

Select this new measure from the Fields list, go to the Measure Tools tab, change the format to Percent:

BA_Pete_0-1674543385466.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @shikhavidyarthi ,

 

Assuming I'm understanding what you're trying to do, I think it would look like this:

if [Criteria] = 1 and [override_reason] = "KEEP"
then List.Count(previousStepName[facility_id]) / List.Count(previousStepName[facility_id])
else 0

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




If criteria = 1 then ( if override_reason = 'KEEP' then count(facility_id))/Count(facility_id) else 0

Hi @shikhavidyarthi ,

 

That's what my code does.

If it's not doing what you're expecting it to do, can you give me some more detail around what you need please?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors