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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
ALobo94
New Member

Dynamic difference between dates present in a single column based on slicer selection

Hi,

I have a sample data in the following format in an excel.

Serial NoTax InvoiceStage 1Stage 2Stage 3
1T13/23/20243/27/20244/6/2024
2T23/28/20244/27/20244/29/2024
3T34/1/20244/15/20244/16/2024

The data represents invoices which is tracked across 3 different stages of when the invoice reaches the different stages, which are in Date. Here Stage3 > Stage 2> Stage 1

I want the Average Date difference across all invoices between any 2 stages based on a slicer selection between stages.

For Eg: I have a slicer with Stages 1,2 & 3. When I select Stages 1 & 3, I need to get the Average of Date difference between the Stage 3 & Stage 1. 

So I need to get something below for Stage 1 to Stage 3. I just need the average, & it should change based on the stages I choose in the slicer. How do I go about this? Thanks in advance.

InvoiceDate Difference
T114
T232
T315
Avg20.3
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ALobo94 

You can refer to the following solution.

1.It is better that unpivot the column to the following format in power query.

vxinruzhumsft_0-1711330752902.png

2.Create the following measures.

theDateDifference =
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Tax Invoice] IN VALUES ( 'Table'[Tax Invoice] ),
        'Table'[Stage] IN VALUES ( 'Table'[Stage] )
    )
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[Value] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Tax Invoice] IN VALUES ( 'Table'[Tax Invoice] ),
        'Table'[Stage] IN VALUES ( 'Table'[Stage] )
    )
RETURN
    DATEDIFF ( _mindate, _maxdate, DAY )
Date Difference = AVERAGEX(VALUES('Table'[Tax Invoice]),[theDateDifference])

Then put the date difference measure to the visual.

Output

vxinruzhumsft_1-1711330866085.png

Best Regards!

Yolo Zhu

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

3 REPLIES 3
ALobo94
New Member

Thanks v-xinruzhu-msft for the help

Ashish_Mathur
Super User
Super User

Hi,

These measures work

Diff = 1*(max(Data[Date])-MIN(Data[Date]))
Measure = AVERAGEX(VALUES(Data[Tax Invoice]),[Diff])

Hope this helps.

Ashish_Mathur_0-1711332868106.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @ALobo94 

You can refer to the following solution.

1.It is better that unpivot the column to the following format in power query.

vxinruzhumsft_0-1711330752902.png

2.Create the following measures.

theDateDifference =
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Tax Invoice] IN VALUES ( 'Table'[Tax Invoice] ),
        'Table'[Stage] IN VALUES ( 'Table'[Stage] )
    )
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[Value] ),
        ALLSELECTED ( 'Table' ),
        'Table'[Tax Invoice] IN VALUES ( 'Table'[Tax Invoice] ),
        'Table'[Stage] IN VALUES ( 'Table'[Stage] )
    )
RETURN
    DATEDIFF ( _mindate, _maxdate, DAY )
Date Difference = AVERAGEX(VALUES('Table'[Tax Invoice]),[theDateDifference])

Then put the date difference measure to the visual.

Output

vxinruzhumsft_1-1711330866085.png

Best Regards!

Yolo Zhu

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

 

 

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.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.