Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

If Null Condition in Table.Group always failing

Hi, I am trying to get the count of photos in a column using Power Query. I have a table as follows (example): ID ItemName ItemPhotoName ItemPhotoFileType 1001 Tv Photo.jpg .jpg ...
  • v-yanjiang-msft's avatar
    v-yanjiang-msft
    3 years ago

    Hi Anonymous ,

    For your first question, let me explain more about _[ItemPhotoName]{0}.

    _ represent the all the tables you merged. You can modify the code like below to verify, click the Table cell,

    You will see the contens in it.

    _[ItemPhotoName] represent the [ItemPhotoName] column in the merged table. Also verify like this:

    You can see it's a list instead of a value, to convert to a value, you should specify which row you want to get. For the ID 1002, there is only one row, the symbol {} can specify row in the list, {0} means the first row, {1} means the second row, and so on.

    Modify the formula to verify:

    2. You don't need to change the data type of the column, as I don't know the actually data, I give the solution according to situation.

    If it's null:

    = Table.Group(#"Changed Type", {"ID", "ItemName"}, {{"PhotoPerItemCount", each if _[ItemPhotoName]{0} = null then 0 else Table.RowCount(_)}})

    If it's "null":

    = Table.Group(#"Changed Type", {"ID", "ItemName"}, {{"PhotoPerItemCount", each if _[ItemPhotoName]{0} = "null" then 0 else Table.RowCount(_)}})

    If it's blank:

    = Table.Group(#"Changed Type", {"ID", "ItemName"}, {{"PhotoPerItemCount", each if _[ItemPhotoName]{0} = "" then 0 else Table.RowCount(_)}})

     

    Best Regards,
    Community Support Team _ kalyj

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