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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JorgeMolano
Frequent Visitor

Date Diff using date Filter

Hi community, 
I want to create a measure that calculate the days between the oldest date of my table and a day selection based on date filter.


For insance, using the table below, the oldest date is "01/01/2022" and if I select in my date filter (which is from my same table) "01/09/2022" the result should be 8 days, or if I select in the filter "01/05/2022" the result would be 4.


Dates

JorgeMolano_0-1644007703541.png

 

Thanks for you help!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JorgeMolano 

 

What if no selection in the slicer? What do you want to display, the blank? Modify the table and column name accordingly

test = 
VAR CurDate=SELECTEDVALUE(DateTable[Dates])
VAR MinDate = MINX(ALL(DateTable[Dates]),DateTable[Dates])
RETURN
DATEDIFF(MinDate,CurDate,DAY)

 

View solution in original post

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @JorgeMolano ,

 

Based on your description, try the following formula.

M_ = 
VAR a =
    CALCULATE ( MIN ( 'Table'[Date] ), ALL ( 'Table'[Date] ) )
VAR sel_b =
    SELECTEDVALUE ( 'Table'[Date] )
RETURN
    DATEDIFF ( a, sel_b, DAY )

vhenrykmstf_0-1644386128984.pngvhenrykmstf_1-1644386143728.png


If the problem is still not resolved, please point it out. Looking forward to your feedback.


Best Regards,
Henry


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

JorgeMolano
Frequent Visitor

Hi Vera,


Thanks for your support, I tried the measure you shared but only shows a consecutive number per each row, dont calculate the number of days between 2 different dates.

 

Best!

Hi,

The formula suggested by Vera should work for sure.  Make sure you write it as a measure (not a calculated column) and drag that measure to a card visual.


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

Hi @JorgeMolano 

 

It worked here...maybe try ALL(DateTable) instead of the column? Or attach a sample file?

Vera_33_0-1644370612150.png

 

 

Anonymous
Not applicable

Hi @JorgeMolano 

 

What if no selection in the slicer? What do you want to display, the blank? Modify the table and column name accordingly

test = 
VAR CurDate=SELECTEDVALUE(DateTable[Dates])
VAR MinDate = MINX(ALL(DateTable[Dates]),DateTable[Dates])
RETURN
DATEDIFF(MinDate,CurDate,DAY)

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.