Forum Discussion

wemsomba's avatar
wemsomba
New Member
5 months ago
Solved

DATEDIFF DAX

Hello everyone. I want to get the difference in days between two or three columns from two different tables. I have "Name","firstcontact","Secondcontact","ThirdContact", and "FourthContact" as column...
  • lbendlin's avatar
    5 months ago

    Power BI does not think like Excel.  Unpivot your data  to these columns

     

    Name

    Contact

     

    let
        Source = #table(null,{{ "James ", "1/1/2026 01:30:00 ", "1/15/2026 01:30:00 ", "1/17/2026 01:30:00 ", "1/19/2026 01:30:00 "},
    { "Anthony ",  "1/17/2026 01:30:00 ", "1/19/2026 01:30:00 ", "1/21/2026 01:30:00 ", "1/22/2026 01:30:00 "},
    { "Okito ",  "1/17/2026 01:02:00 ", "1/16/2026 01:30:00 ", "1/22/2026 01:30:00 ", "1/31/2026 01:30:00 "}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Contact"),
        #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Column1", "Contact"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Column1", "Name"}}),
        #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Name", type text}, {"Contact", type datetime}})
    in
        #"Changed Type"

     

    That way the number of contacts for each name can be flexible.

    Then you can run the standard math functions against your data, including min and max difference between values

     

    To compare any two names you would use measures that can modify the filter context, or visual calculations.

     

    Oftentimes a visual solution may be easier.

     

    What is your expected outcome based on the sample data you provided?