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
julien-rivley
Helper I
Helper I

Calculate future expiry of product

Hello,

 

I'm trying to calculate the future stock expiry for each of the future months with the following data:

- current month opening stock by expiry date
- demand of the current and all the future months

I believe to have found a way to calculate it to calculate it but I'm stuck at combining 2 table, here are the details
Current month opening stock table by expiry date:

YearMonthCurrent month stock by expiry date
Jan-201000
Mar-20450
May-201000
Oct-20100


Demand table:

YearMonthDemandCumulated Demand
Jul-19100100
Aug-19100200
Sep-19100300
Oct-19100400
Nov-19100500
Dec-19100600
Jan-20100700
Feb-20100800
Mar-20100900
Apr-201001000
May-201001100
Jun-201001200
Jul-201001300
Aug-201001400
Sep-201001500
Oct-201001600
Nov-201001700
Dec-201001800
Jan-211001900
Feb-211002000
Mar-211002100


What I would like:

YearMonthCurrent month stock by expiry dateCumulated demand
Jan-201000700
Mar-20450900
May-2010001100
Oct-201001600



My issue is that "YearMonth" in the 2 tables are not related in the data model... is there any way to join these 2 tables? I tried NATURALLEFTOUTERJOIN but it doesn't seem to work.

Thanks,

Julien

1 ACCEPTED SOLUTION
dearwatson
Responsive Resident
Responsive Resident

Hi Julien, 

 

You can build a measure that first gets the "CurrentYearMonth" then filters the second table to return only that row and sum the cumulated demand:

 

Cumulated Demand = 
VAR CurrentYearMonth =
    MAX ( Table1[YearMonth] )
RETURN
    CALCULATE (
        SUM ( Table2[Cumulated Demand] ),
        FILTER ( Table2, Table2[YearMonth] = CurrentYearMonth )
    )

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte

View solution in original post

2 REPLIES 2
dearwatson
Responsive Resident
Responsive Resident

Hi Julien, 

 

You can build a measure that first gets the "CurrentYearMonth" then filters the second table to return only that row and sum the cumulated demand:

 

Cumulated Demand = 
VAR CurrentYearMonth =
    MAX ( Table1[YearMonth] )
RETURN
    CALCULATE (
        SUM ( Table2[Cumulated Demand] ),
        FILTER ( Table2, Table2[YearMonth] = CurrentYearMonth )
    )

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte

Thanks for the help!

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.