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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DSwezey
Helper III
Helper III

Calculate number of days between Selected Date and another Table

I have an Invoice table that has "InvoicedDate".

I have a date table as well.

The date table and the Invoice table are related on 'Date'[Date] ----> 'Invoice'[InvoicedDate]

On my dashboad I have a date slicer via 'Date'[Date] that when I change I want to count the number of days between the Max('Date'[Date]) and the 'InvoicedDate' per invoice.

 

I tried using Datediff, but was unsuccessful. 

 

I also need this to be a measure rather than a calculated column. 

Any help would be appreciated. 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @DSwezey ,

 

Please delete the relationship or make the relationship inactive between 'Date'[Date] and 'Invoice'[InvoicedDate]

Eyelyn9_0-1657520706819.png

Output:

Eyelyn9_1-1657520725074.png

Best Regards,
Eyelyn Qin
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
v-eqin-msft
Community Support
Community Support

Hi @DSwezey ,

 

Please delete the relationship or make the relationship inactive between 'Date'[Date] and 'Invoice'[InvoicedDate]

Eyelyn9_0-1657520706819.png

Output:

Eyelyn9_1-1657520725074.png

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

johnt75
Super User
Super User

Your date slicer would filter a table visual to only show those invoices which have an invoice date matching the slicer selection. If that is not the behviour you want you can either use Edit Interactions to disable the date slicer from filtering the table visual, or you can create a new date table just for the slicer and have no relationship from that to the invoice table.

To get the number of days between the invoice date and the date in your slicer you can create a measure like

Days diff = CALCULATE(
DATEDIFF( MAX('Date'[Date]), SELECTEDVALUE('Invoice'[Invoice Date]),
REMOVEFILTERS('Date')
)

So I was able to get a measure working that calculates the amount of days between the MAX('date') and min('invoice'[date]) but this only gives me the difference between the "First" invoice date. It does not calculate it for each invoice date for each invoice number.

 

Days Diff = 
var firstday = MIN('INVOICE'[InvoiceDateTime])
var LastDay = MAX('DateTable'[Date])
return
datediff(firstday,LastDay,DAY

I've tried something similar to this but I still get (Blank) returned. Still not sure why this is happening

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors