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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PerpetualGrad
Frequent Visitor

Power Query Custom Columns: How can I reduce the repetitiveness of my syntax?

Hi there:

 

I am new to PBI and know that there must be a way that I can reduce the repetitiveness of my code when creating a custom conditional column. Currently I am re-writing the same code structure to indicate if any single individual category equals 1 and the other values are 0, then the result is "1 Category", and repeating these combinations all the way up to "4+ Categories" and the result should be mutually exclusive. Example below. I would LOVE a simpler way to do this if possible and I have been overthinking this to my detriment, thanks!

 

= if
[Category1] =1 and (
[Category2] =0 and
[Category3]=0 and
[Category4]=0 and
[Category5]=0 and
[Category6]=0 ) then "1 Category"

else if
[Category2] =1 and (
[Category3]=0 and
[Category4]=0 and
[Category5]=0 and
[Category6]=0 and 
[Category1] =0) then "1 Category"
.
.
.
else if 
[Category1] =1 and [Category2] =1 and (
[Category3]=0 and
[Category4]=0 and
[Category5]=0 and
[Category6]=0 ) then "2 Categories"
 
... and so on until all combination of catoegies have been accounted for.
 

 

1 REPLY 1
mangaus1111
Solution Sage
Solution Sage

Hi @PerpetualGrad ,

see if my pbi file can help you.

https://1drv.ms/u/s!Aj45jbu0mDVJi2da_Op1RvvBu_Ky?e=VMXD5N

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.