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
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

Anonymous
Not applicable

I have tried to elaborate the question.

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.