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

Join 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.

Reply
Aucesar
Helper III
Helper III

Power Query new column not working for "not in" values

Hi Community (me again);

I build a powerquery that works (80%) so I´m asking for help to made it to work 100%

Have a table with codes and I need to create a new column based on these codes.

Code below:

 

= Table.AddColumn(#"dbo_BI-Despesas", "Custom",
each if [nCodGrPg] = 1003 then "Despesas"
else if [nCodGrPg] = 12 then "Investimentos"
else if [nCodGrPg] = 1000 or [nCodGrPg] = 1001 or [nCodGrPg] = 1002 then "Gastos"
// (This line isn´t working, it doesn´t filter the data as expected, should ALL except the filtered values "<>" , what I´m doing wrong"?) // else if [nCodClPg] <> 999 or [nCodClPg] <> 201 and [nCodGrPg] <> 1000 or [nCodGrPg] <> 1001 or [nCodGrPg] <> 1002 or [nCodGrPg] <> 1003 or [nCodGrPg] <> 21 or [nCodGrPg] <> 999 or [nCodGrPg] <> 201 then "Custos"
else if [nCodClPg] <> 999 then "Despesas-Geral-999"
else if [nCodClPg] <> 201 then "Despesas-Geral-201"
else "Null")

 

Thanks in Advance

1 ACCEPTED SOLUTION

@Mahesh0016  this link have sample data https://we.tl/t-LS6g2O4qhg, you will see in the "classificação" column four types, but the filter for "Custos" isn´t working as expected, another two examples below which are working:
DAX:

CALCULATE (
    SUM ( 'BI-Despesas'[nVlrNomiB] ) + SUM ( 'BI-Despesas'[nVlrJuroB] )
        - SUM ( 'BI-Despesas'[nVlrAbatB] ),
    NOT 'BI-Despesas'[nCodClPg] IN { 201, 999 },
    NOT 'BI-Despesas'[nCodGrPg] IN { 1001, 1002, 1003 }
)
Just to show in visual what is wrong, using DAX the value is R$19..... but with the filter on PowerQuery the value is bigger, which means the new column is not classified as I expected using this powerquery
Aucesar_0-1681818830314.png

 

fell free to ask if you still have question, thanks in advance!

View solution in original post

2 REPLIES 2
Mahesh0016
Super User
Super User

@Aucesar please can you share demo dataset or result you want.
Thank You!

@Mahesh0016  this link have sample data https://we.tl/t-LS6g2O4qhg, you will see in the "classificação" column four types, but the filter for "Custos" isn´t working as expected, another two examples below which are working:
DAX:

CALCULATE (
    SUM ( 'BI-Despesas'[nVlrNomiB] ) + SUM ( 'BI-Despesas'[nVlrJuroB] )
        - SUM ( 'BI-Despesas'[nVlrAbatB] ),
    NOT 'BI-Despesas'[nCodClPg] IN { 201, 999 },
    NOT 'BI-Despesas'[nCodGrPg] IN { 1001, 1002, 1003 }
)
Just to show in visual what is wrong, using DAX the value is R$19..... but with the filter on PowerQuery the value is bigger, which means the new column is not classified as I expected using this powerquery
Aucesar_0-1681818830314.png

 

fell free to ask if you still have question, thanks in advance!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.