Forum Discussion

romoguy15's avatar
romoguy15
Icon for Helper IV rankHelper IV
5 years ago
Solved

Distinct Count # of unique dates based on column with duplicates

Hello Everyone,   I have a two column table, one with ticket IDs and another with dates. The first column of ticket IDs could have uniqe or duplicate ticket IDs. The other date column could have al...
  • Ashish_Mathur's avatar
    Ashish_Mathur
    5 years ago

    Hi,

    This should typically be done directly in the visual but if you must do it in the Query Editor, then this M code works

    let
        Source = Excel.Workbook(File.Contents("C:\Users\mathu\Desktop\try.xlsx"), null, true),
        #"Removed Other Columns" = Table.SelectColumns(Source,{"Data"}),
        #"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns", "Data", {"Column1", "Column2"}, {"Data.Column1", "Data.Column2"}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Expanded Data", [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Ticket Id", type text}, {"Ticket Closed Date", type date}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Ticket Id", Order.Ascending}}),
        #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Ticket Id"}, {{"Count", each Table.RowCount(Table.Distinct(_)), type nullable date}})
    in
        #"Grouped Rows"