Forum Discussion

twister8889's avatar
twister8889
Helper V
4 years ago
Solved

Convert null dates to all dates existing into table

Hi guys,   I have a table that contains User and Date columns for example, and the dates can be null because I am doing a left join for users table. I would like that when the user doesn't have a ...
  • PaulDBrown's avatar
    4 years ago

    Try this in a new table:

     

     

    New Table =
    VAR _Dates =
        DISTINCT ( OriginalTable[Date] )
    VAR _BlankVal =
        CALCULATETABLE (
            VALUES ( OriginalTable[User] ),
            FILTER ( OriginalTable, ISBLANK ( OriginalTable[Date] ) )
        )
    VAR _AssignDates =
        FILTER ( CROSSJOIN ( _BlankVal, _Dates ), NOT ( ISBLANK ( [Date] ) ) )
    VAR _OrigOK =
        FILTER ( OriginalTable, NOT ( ISBLANK ( OriginalTable[Date] ) ) )
    RETURN
        UNION ( _OrigOK, _AssignDates )
    

     

     

     

    Or this in Power Query (you will need to use your source table code for Source and Source1 lines)

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1AciIwMjQ6VYHaiQEYqQM0jIGEXICSikFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Date", type date}}),
        #"GoodRows" = Table.SelectRows(#"Changed Type", each ([Date] <> null)),
        Source1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1AciIwMjQ6VYHaiQEYqQM0jIGEXICSikFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Date = _t]),
        #"Changed Type1" = Table.TransformColumnTypes(Source1,{{"User", type text}, {"Date", type date}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Date] = null)),
        #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Date"}),
        #"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each #"GoodRows"),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Date"}, {"Custom.Date"}),
        #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom.Date", "Date"}}),
        #"Appended Query" = Table.Combine({#"GoodRows", #"Renamed Columns"}),
        #"Changed Type2" = Table.TransformColumnTypes(#"Appended Query",{{"Date", type date}})
        
    in
        #"Changed Type2"