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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Comparing dates from two different tables

I have 2 tables, the first contains all the transactions(TransactionTable) and the second one contains all the dates (DateTable) from 1st Jan 2018 to 31st Dec 2021.

 

I have a expired date for each batch of my products stored in the inventory. I want to write a measure to calculate difference between expiry date and the date in the DateTable, to determine expired products. I have a seperate table for dates and the expiry date is in my transactions table. How to I compare dates from two different tables?

 

I want to plot a graph of Number of Expired products against the date. So I want to know on a certain date, how many products in stock will be expired. Store Transactions TableStore Transactions Table

 

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Shouldn't the expiration date of the product be compared with today?

__DateDiff = 
DATEDIFF(
    TODAY(),
    MAX(Sheet1[expiration_date]),
    DAY
)
__Number of expiration = 
CALCULATE(
    COUNT(Sheet1[Product_id]),
    FILTER(
        Sheet1,
        [__DateDiff] < 0 
    )
)

v-lionel-msft_0-1597732234845.png

 

Best regards,
Lionel Chen

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

Hi @Anonymous ,

 

Has your problem been solved?

 

Best regards,
Lionel Chen

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

AllisonKennedy
Super User
Super User

@Anonymous
I don't understand what you mean?

You need to have a way to relate/link the Date and the transaction table. If you want to plot the number of expired products against date, you just need to create a relationship between expiry date and the date in your date table.

Then put Month or date[date] and transaction[item] in the visual with summarization of item set to COUNT.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@Anonymous , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Date diff = datediff(min(Transacation[Expiry Date]), Max(Date[Date]),Day)

But you need to force a context using values or summarize

Refer for context

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Difference-Across/ba-p/934397#M451

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

I have tried to elaborate the question.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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