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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pwrch
Frequent Visitor

Measure with a loop to calculate future product stock

Hi,

 

I have a table of items and the date they'll be in stock and I have another table that lists how many of each item we'll be getting over the next year or so. For example:


Table A:

ItemsDate
A7/1/2022
B8/1/2022


Table B:

DateQuantity
7/1/202250
8/1/2022100
9/1/202250
10/1/202275

etc.

What I want to do is create a measure that looks up when an item will be in stock (from table A) and then loops month by month after that date using the quanity from Table B to return a date when I will have X amount of product available.

 

Thank you,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @pwrch ,

 

Here I create a sample to have a test.

Table A:

RicoZhou_0-1654238638058.png

Table B:

RicoZhou_1-1654238642675.png

Use What-if parameter to create a slicer. We can select the target number in it.

RicoZhou_3-1654238685767.png

Measure:

Running Total = 
CALCULATE (
    SUM ( 'Table B'[Quantity] ),
    FILTER (
        ALL ( 'Table B' ),
        'Table B'[Date] >= MAX ( 'Table A'[Date] )
            && 'Table B'[Date] <= MAX ( 'Table B'[Date] )
    )
)
Date meet target = 
VAR _Target =
    SELECTEDVALUE ( Parameter[Parameter] )
RETURN
    CALCULATE (
        MIN ( 'Table B'[Date] ),
        FILTER ( ALL ( 'Table B'[Date] ), [Running Total] >= _Target )
    )

Result is as below.

Here I select 200 in slicer. So Item A will meet this target in 2022/09/01 and Item will meet this target in 2022/10/01.

RicoZhou_4-1654238766839.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

not quite sure what you are after, but assuming you want to sum the values Table B for all months after the date in Table A, you can use this approach: pbix

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

 

How to Get Your Question Answered Quickly

Kindoff yes. I want to add up the values thaat come after but only until they certain value (like for example 1000) and then return the date when that happens.

Anonymous
Not applicable

Hi @pwrch ,

 

Here I create a sample to have a test.

Table A:

RicoZhou_0-1654238638058.png

Table B:

RicoZhou_1-1654238642675.png

Use What-if parameter to create a slicer. We can select the target number in it.

RicoZhou_3-1654238685767.png

Measure:

Running Total = 
CALCULATE (
    SUM ( 'Table B'[Quantity] ),
    FILTER (
        ALL ( 'Table B' ),
        'Table B'[Date] >= MAX ( 'Table A'[Date] )
            && 'Table B'[Date] <= MAX ( 'Table B'[Date] )
    )
)
Date meet target = 
VAR _Target =
    SELECTEDVALUE ( Parameter[Parameter] )
RETURN
    CALCULATE (
        MIN ( 'Table B'[Date] ),
        FILTER ( ALL ( 'Table B'[Date] ), [Running Total] >= _Target )
    )

Result is as below.

Here I select 200 in slicer. So Item A will meet this target in 2022/09/01 and Item will meet this target in 2022/10/01.

RicoZhou_4-1654238766839.png

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors