Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Show continuous date and reflect '0' for missing data

Hi All   I think I might have accidentally double post and marked as spam, I have deleted the previous thread I have the below table which contain delivery information - the date of delivery, for ...
  • v-alq-msft's avatar
    5 years ago

    Hi, Anonymous 

     

    Based on your description, I created data to reproduce your scenario, The pbix file is attached in the end.

    Table:

     

    You may create a new query and paste the following codes in 'Advanced Editor'.

    let
        Source = let mindate=List.Min(Table[Delivered Date]),maxdate=List.Max(Table[Delivered Date]) in
    List.Dates(
        mindate,
        Duration.Days( maxdate-mindate)+1,
        #duration(1,0,0,0)
    ),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Delivered Date"}}),
        #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Cust", each Table.Distinct(
        Table.FromList( Table[Cust No],Splitter.SplitByNothing(),null,null,ExtraValues.Error )
    )),
        #"Expanded Cust" = Table.ExpandTableColumn(#"Added Custom", "Cust", {"Column1"}, {"Cust.Column1"}),
        #"Added Custom1" = Table.AddColumn(#"Expanded Cust", "Custom", each let 
    date = [Delivered Date],cust=[Cust.Column1],
    tab = Table.SelectRows(
        Table,
        each [Delivered Date]=date and 
        [Cust No]=cust
    )[Doc No]
    in 
    tab
    ),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
        #"Added Custom2" = Table.AddColumn(#"Expanded Custom", "Custom.1", each let 
    date = [Delivered Date],cust=[Cust.Column1],
    c=[Custom],
    val = List.Sum( Table.SelectRows(
        Table,
        each [Delivered Date]=date and 
        [Cust No]=cust and 
        [Doc No]=c
    )[Vol]
    )
    in 
    if val=null 
    then 0
    else val 
    ),
        #"Renamed Columns1" = Table.RenameColumns(#"Added Custom2",{{"Cust.Column1", "Cust No."}, {"Custom", "Doc No."}, {"Custom.1", "Vol"}})
    in
        #"Renamed Columns1"

     

     

    Result:

     

    Best Regards

    Allan

     

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