Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
wemsomba
New Member

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 columns. I want to be able to to have two filters for the contacts so i can see the difference in days between each contacts. I have the same code uploaded in power bi as two different data sets. one is selected the other is compared. I unpivotted all 4 contact colums in power query to have them as Attribute column (which has 1st...4th contact as values of the column) and Value (which has dates as values of the column) also as fields. I have created two filters with the contact columns that i unpivotted. One will be Selected filter and the other Compared filter.

Now i want to have this outcome . I WANT TO BE ABLE TO COMPARE ANY CONTACT FROM SELECTED FILTER TO ANY FROM COMPARED FILTER. I have the DAX below but power bi not recognizing the values. please help. below is also the code.

DATE DIFF = DATEDIFF(Selected[Value], Compared[Value])

 

create table Selected(
Name varchar(30), FirstContact datetime,SecondContact datetime,ThirdContact datetime,FourthContact datetime)
 
insert into Selected (Name,FirstContact,SecondContact,ThirdContact,FourthContact)
VALUES
('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')
SELECT *FROM Selected
DROP TABLE Selected
 
 
create table Compared(
Name varchar(30), FirstContact datetime,SecondContact datetime,ThirdContact datetime,FourthContact datetime)
 
insert into Compared (Name,FirstContact,SecondContact,ThirdContact,FourthContact)
VALUES
('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')
SELECT *FROM Compared
DROP TABLE Compared
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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.

lbendlin_0-1771688665579.png

 

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

 

 

View solution in original post

3 REPLIES 3
v-nmadadi-msft
Community Support
Community Support

Hi @wemsomba 

May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.


Thank you

v-nmadadi-msft
Community Support
Community Support

Hi @wemsomba 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.


Thank you.

lbendlin
Super User
Super User

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.

lbendlin_0-1771688665579.png

 

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

 

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.