Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
Solved! Go to 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:
Pete
Proud to be a Datanaut!
Hi,
I want the result as bottom screenshot.
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:
Pete
Proud to be a Datanaut!
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
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
Proud to be a Datanaut!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
13 | |
12 | |
9 | |
8 |
User | Count |
---|---|
17 | |
9 | |
8 | |
7 | |
7 |