Forum Discussion

Junaid11's avatar
Junaid11
Icon for Helper V rankHelper V
4 years ago
Solved

Condition If Date column is empty against Id

Hello, I want to create a column in which I want if Date is there against ID then it should show Ready otherwise not ready. If ID is same and one cell has date and other opposite cell does not have ...
  • danextian's avatar
    4 years ago

    Hi Junaid11 ,

    Aside from merging queries like jsaunders_zero9  has suggested is using the Table.Group function in Power Query.

    • First a custom column is created that will return 1 if [ID]  is null.
    • Second, the whole table is grouped by [ID] so that transforms the current table into two columns: [ID] and another column with tables that contains all the records prior to grouping.
    • Third, create a custom column that will sum column created in the first step per row ID.
    • Last, expand the column of tables created in the second step to show just the date.

       

    Here 's a sample M Script to be pasted on a blank query:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMtY3MNI3MjAyVIrVgYoZWugbGILEDCBiRkAxBQQTKGdgCZWOBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "BlankDate", each if [Date] = null then 1 else null, Int64.Type),
        #"Grouped Rows" = Table.Group(#"Added Custom", {"ID"}, {{"Count", each _, type table [ID=nullable text, Date=nullable date, BlankDate=number]}}),
        #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Ready/Not Ready", each if List.Sum([Count][BlankDate]) <> null then "Not Ready" else "Ready", type text),
        #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Count", {"Date"}, {"Date"})
    in
        #"Expanded Count"

     

     

    Alternatively, you can create a calculated column using DAX that will scan the table and return whether there is a blank date per row id.

     

     

    Ready/Not Ready = 
    VAR CountOfBlank =
        CALCULATE (
            COUNTBLANK ( 'Table (3)'[Date] ),
            ALLEXCEPT ( 'Table (3)', 'Table (3)'[ID] )
        )
    RETURN
       IF ( CountOfBlank > 0, "Not Ready", "Ready" )