Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
I need to create custom column in the PowerBI using conditional statement. My condition is if reference column value is less than 5 then populate value as 0-5 Years, if reference column value is less than 15 then populate value as 5-15 Years and if reference column value is greater than 15 then populate value as Over 15 Years. How could I write syntax for this condition in PowerBI.

Please help. I can do this in excel with help of below formula.

=IF([@[Yrs_pg]]<5,"0-5 Years",IF([@[Yrs_pg]]<15,"5-15 Years",IF([@[Yrs_pg]]>15,"Over 15 Years")))

What I have tried:

=IF([@[Yrs_pg]]<5,"0-5 Years",IF([@[Yrs_pg]]<15,"5-15 Years",IF([@[Yrs_pg]]>15,"Over 15 Years")))
Posted

1 solution

If you click on Add Column, then Conditional Column
Ater the If select your reference Column Name, Operator 'is less than' and Value 5. Output '0-5 Years'
Click on Add Clause
Select your Reference Column Name, Operator 'is less than' and Value 15. Output '5-15 Years'
Then in the Else section type 'Over 15 Years'

Alternatively use Add Column, Custom Column and type into the formula box
VB
if [Reference] < 5 then "0-5 Years" else if [Reference] < 15 then "5-15 Years" else "Over 15 Years"

Reference: M Language Conditionals - PowerQuery M | Microsoft Learn[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900