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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

DateDiff using slicers

Hello All,

I have a column of Task Names and a column of task dates. I would like to create a report that allows users to select two different tasks and determine the number of days between those two task dates. 

 

Column A = Task Name

Column B = Task Date

I would need slicers to allow users to pick two tasks (presumably two separate slicers, and thinking they would be from two separate tables. 

 

Desired Resulting Table

Task 1 Name  ,  Task 2 Name   ,   Date Difference Header

Task 1 Date    ,  Task 2 Date     ,   Date Difference in Days

 

I've tried several approaches so far and haven't been able to figure this out. Any help would be appreciated. 

2 ACCEPTED SOLUTIONS
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check:

 

1. Enter data to create ColumnHeader1 table. The order is the count of task name +1.

col.PNG

 

2. Create ColumnHeader2 table.

ColumnHeader2 = 
UNION (
    ADDCOLUMNS (
        VALUES ( 'Table'[Task Name] ),
        "Order", CONVERT ( RIGHT ( [Task Name], SEARCH ( " ", [Task Name] ) - 3 ), INTEGER )
    ),
    ColumnHeader1
)

sorttask.jpg

 

3. Create a slicer table.

Task Name Slicer = VALUES('Table'[Task Name])

 

4. Create measures.

Date Difference in Days = 
VAR T1 =
    MIN ( 'Task Name Slicer'[Task Name] )
VAR T1_Date =
    CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = T1 )
VAR T2 =
    MAX ( 'Task Name Slicer'[Task Name] )
VAR T2_Date =
    CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = T2 )
RETURN
    DATEDIFF ( T1_Date, T2_Date, DAY )
Value Measure = 
VAR Task_ =
    MAX ( 'ColumnHeader2'[Task Name] )
RETURN
    IF (
        Task_ = "Date Difference in Days",
        [Date Difference in Days],
        CONVERT (
            CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = Task_ ),
            STRING
        )
    )
Measure = 
IF (
    MAX ( 'ColumnHeader2'[Task Name] ) = "Date Difference in Days",
    1,
    IF (
        MAX ( 'ColumnHeader2'[Task Name] ) IN VALUES ( 'Task Name Slicer'[Task Name] ),
        1
    )
)

 

5. Create a Matrix visual.

matrix.PNG

 

6. Then, you will get this:

diff.gif

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

View solution in original post

Icey
Community Support
Community Support

Hi @Anonymous ,

 

You can create your ColumnHeader1 table like this:

ColumnHeader1 =
ADDCOLUMNS (
    DATATABLE ( "ColumnHeader", STRING, { { "Date Difference in Days" } } ),
    "Order", DISTINCTCOUNT ( 'Table'[Task Name] ) + 1
)

columnheader.PNG

 

 

Best Regards,

Icey

 

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

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check:

 

1. Enter data to create ColumnHeader1 table. The order is the count of task name +1.

col.PNG

 

2. Create ColumnHeader2 table.

ColumnHeader2 = 
UNION (
    ADDCOLUMNS (
        VALUES ( 'Table'[Task Name] ),
        "Order", CONVERT ( RIGHT ( [Task Name], SEARCH ( " ", [Task Name] ) - 3 ), INTEGER )
    ),
    ColumnHeader1
)

sorttask.jpg

 

3. Create a slicer table.

Task Name Slicer = VALUES('Table'[Task Name])

 

4. Create measures.

Date Difference in Days = 
VAR T1 =
    MIN ( 'Task Name Slicer'[Task Name] )
VAR T1_Date =
    CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = T1 )
VAR T2 =
    MAX ( 'Task Name Slicer'[Task Name] )
VAR T2_Date =
    CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = T2 )
RETURN
    DATEDIFF ( T1_Date, T2_Date, DAY )
Value Measure = 
VAR Task_ =
    MAX ( 'ColumnHeader2'[Task Name] )
RETURN
    IF (
        Task_ = "Date Difference in Days",
        [Date Difference in Days],
        CONVERT (
            CALCULATE ( MAX ( 'Table'[Task Date] ), 'Table'[Task Name] = Task_ ),
            STRING
        )
    )
Measure = 
IF (
    MAX ( 'ColumnHeader2'[Task Name] ) = "Date Difference in Days",
    1,
    IF (
        MAX ( 'ColumnHeader2'[Task Name] ) IN VALUES ( 'Task Name Slicer'[Task Name] ),
        1
    )
)

 

5. Create a Matrix visual.

matrix.PNG

 

6. Then, you will get this:

diff.gif

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

@Icey ,

Thank you for the incredibly detailed response, which looks like it will solve my issue beautifully. The only challenge I have in getting started is that my # of tasks may change. You mentioned needing to set ColumnHeader1 Table to a value of Count Tasks +1. If this is dynamic, how would I go about this?

FYI I have an append process which is adding tasks from another source and is why this may be dynamic.

Thank you again and looking forward to your response.

Icey
Community Support
Community Support

Hi @Anonymous ,

 

You can create your ColumnHeader1 table like this:

ColumnHeader1 =
ADDCOLUMNS (
    DATATABLE ( "ColumnHeader", STRING, { { "Date Difference in Days" } } ),
    "Order", DISTINCTCOUNT ( 'Table'[Task Name] ) + 1
)

columnheader.PNG

 

 

Best Regards,

Icey

 

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

lbendlin
Super User
Super User

Yes, you need two independent tables (you could import the table once and then in Power Query create a reference)

 

Assign the tasks to their slicers, make each slicer single selection and then create a measure somewhere that says

 

diff = selectedvalue(table1[date])-selectedvalue(table2[date])

 

or use DATEDIFF() if you must.

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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