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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
AmeenVanakar
Advocate II
Advocate II

Unable to get the number of days between 2 dates in a calculated table - Need Help

Hi,

I have created a table showing all the barcodes available in the warehouse but I cannot get the date difference between the purchase date (corresponding to the barcode) and today. Can you please help?

 

Stock_Age = DATEDIFF(SUMMARIZE(RELATEDTABLE(Warehouse_Stock),Warehouse_Stock[PURCHASE DATE]),TODAY(),DAY)
 
The lookup is the unique barcode that is created using the below simple formula.
 
 AmeenVanakar_0-1728112649207.png
 
2 ACCEPTED SOLUTIONS
dharmendars007
Super User
Super User

Hello @AmeenVanakar , 

 

Please try the below formula and please make sure the Puchase date is in date format.

 

Stock_Age = DATEDIFF(Warehouse_Stock[PURCHASE DATE], TODAY(), DAY)

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

View solution in original post

elitesmitpatel
Super User
Super User

Hey @AmeenVanakar 
Please  make some changes in measure 

Stock_Age =
 DATEDIFF(RELATED(Warehouse_Stock[PURCHASE DATE]),TODAY(),DAY)

Stock Age Range =
SWITCH(
    TRUE(),
    'Stock Age Table'[Stock_Age]>=365, "Above 365",
    'Stock Age Table'[Stock_Age]>=181, "Above 180",
    'Stock Age Table'[Stock_Age]>=151, "151-180",
    'Stock Age Table'[Stock_Age]>=121, "121-150",
    'Stock Age Table'[Stock_Age]>=91, "91-120",
    'Stock Age Table'[Stock_Age]>61, "61-90",
    'Stock Age Table'[Stock_Age]>31, "31-60",
    "Below 0-30"
)

elitesmitpatel_0-1728126202838.png

Please Kudos and Accept it as solution so other community member get helped
Thank You

View solution in original post

8 REPLIES 8
AmeenVanakar
Advocate II
Advocate II

Thanks @elitesmitpatel and @dharmendars007  the solution worked!

elitesmitpatel
Super User
Super User

Hey @AmeenVanakar 
Please  make some changes in measure 

Stock_Age =
 DATEDIFF(RELATED(Warehouse_Stock[PURCHASE DATE]),TODAY(),DAY)

Stock Age Range =
SWITCH(
    TRUE(),
    'Stock Age Table'[Stock_Age]>=365, "Above 365",
    'Stock Age Table'[Stock_Age]>=181, "Above 180",
    'Stock Age Table'[Stock_Age]>=151, "151-180",
    'Stock Age Table'[Stock_Age]>=121, "121-150",
    'Stock Age Table'[Stock_Age]>=91, "91-120",
    'Stock Age Table'[Stock_Age]>61, "61-90",
    'Stock Age Table'[Stock_Age]>31, "31-60",
    "Below 0-30"
)

elitesmitpatel_0-1728126202838.png

Please Kudos and Accept it as solution so other community member get helped
Thank You

dharmendars007
Super User
Super User

Hello @AmeenVanakar , 

 

Please try the below formula and please make sure the Puchase date is in date format.

 

Stock_Age = DATEDIFF(Warehouse_Stock[PURCHASE DATE], TODAY(), DAY)

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Hi @dharmendars007 

No luck! It's still throwing errors. I am looking for the date difference corresponding to the unique barcodes

 

AmeenVanakar_0-1728113516274.png

 

Please share the Dummy Pbix file

Hey @AmeenVanakar 
Here is the solution 
Just made the relationship between these two tables 

elitesmitpatel_0-1728118859143.png

then the measure mentioned by @dharmendars007  will work and you will get the expected output

PBIX File link 
Unable-to-get-the-number-of-days-between-2-dates-in-a-calculated Solved 

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

Thanks @elitesmitpatel 

I also noticed that you have made changes to the "Stock age range" column & it seems to be a circular reference. Any idea how to solve this? I need to use this column as a filter.

 

AmeenVanakar_2-1728123196266.png

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors