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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Table.SelectRows in conjunction with if statement from another table

Hi,

 

 Trying to utilise an if statement within a Table.SelectRows and not having any joy, had a good look around and can't quite find the right thing....

 

So table Inventory(90+) lists all inventory line data and has 2 additional columns CSR and REP

I've created a "Home" tab with 2 tables (named CSR and REP) turn them into lists and add to the query so that the users can populate either one of these then automatically filter the data as required.

From there I want to filter the Inventory(90+) table based on whichever the user has populated. So let say I only wanted to filter by 1 criteria I use  = Table.SelectRows(#"Sorted Rows", each ([CSR] = CSR))  and that works fine but now I want to do that but if CSR = null then filter [REP] = REP.

 

I tried = Table.SelectRows(#"Sorted Rows", each (if CSR <> null then CSR else REP)) but I get error saying "We cannot convert value "BigJim" into type Logical" but I wasn't surprised by as that doesn't look right.

 

Then I tried 

= Table.SelectRows(#"Sorted Rows", each if CSR = null
then Table.SelectRows(#"Sorted Rows", each [REP] = REP)
else Table.SelectRows(#"Sorted Rows", each [CSR] = CSR))

but get a similar error "We cannot convert a value of type Table to type Logical"

 

Hope the above makes sense on what I'm trying to achieve and any help would be appreciated!

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Assuming that your REP and CSR are values and not tables, and you want to use one conditional statement, you would do it like this...

 

= Table.SelectRows(#"Sorted Rows", each if CSR = null
then [REP] = REP else [CSR] = CSR )

 

Example:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUpRitWJVkoCslLhrDQwKxnISgezUuCsVCArQyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CSR = _t, REP = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CSR", type text}, {"REP", type text}}),
    CSR = null, //"b",
    REP = "h",
    SelectRows = Table.SelectRows(#"Changed Type" , each if CSR = null then [REP] = REP else [CSR] = CSR )
in
    SelectRows

View solution in original post

7 REPLIES 7
jennratten
Super User
Super User

Assuming that your REP and CSR are values and not tables, and you want to use one conditional statement, you would do it like this...

 

= Table.SelectRows(#"Sorted Rows", each if CSR = null
then [REP] = REP else [CSR] = CSR )

 

Example:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUpRitWJVkoCslLhrDQwKxnISgezUuCsVCArQyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CSR = _t, REP = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CSR", type text}, {"REP", type text}}),
    CSR = null, //"b",
    REP = "h",
    SelectRows = Table.SelectRows(#"Changed Type" , each if CSR = null then [REP] = REP else [CSR] = CSR )
in
    SelectRows
Anonymous
Not applicable

Thank you this worked pefectly! Makes sense to write it like that now I see it 🙂

Anonymous
Not applicable

non è assolutamente chiaro quello che cerchi.

sarebbe utile se caricassi delle tabelle di esempio.

Provo ad indovinare 🎰, comunque ...

 

se ti funziona  Table.SelectRows(#"Sorted Rows", each ([CSR] = CSR))  

allora prova  con Table.SelectRows(#"Sorted Rows", each ([CSR] = CSR or [REP] = REP ))  

jennratten
Super User
Super User

Hello - I think the problem is in this part of the script:

each if CSR = null

This is evaluating whether or not CSR is a null object, not a table without rows.  Pls try replacing that portion of the script with one of these options:

each if Table.RowCount(CSR)>0

OR

each if Table.IsEmpty(CSR)

  

Anonymous
Not applicable

Hi Jennratten,

 

 Unfortunatley both of those give me "We cannot convert the value null to type Table."

= Table.SelectRows(#"Sorted Rows", each if Table.IsEmpty(CSR)
then Table.SelectRows(#"Sorted Rows", [REP] = REP)
else Table.SelectRows(#"Sorted Rows", [CSR] = CSR))

 

adding a screenshot of the CSR table drilldown incase I've gone wrong there but as before it works fine when using 1 criteria:

 

let
Source = Excel.CurrentWorkbook(){[Name="CSR"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CSR", type text}}),
#"Uppercased Text" = Table.TransformColumns(#"Changed Type",{{"CSR", Text.Upper, type text}}),
CSR = #"Uppercased Text"{0}[CSR]
in
CSR

Capture.PNG

It looks like REP is a value of type text.  Is CSR also a text value when it is populated?

Anonymous
Not applicable

Yea both Tables/Lists are set as type Text and the columns are also type Text

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors