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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.