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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sy898661
Helper V
Helper V

rolling inventory over time

Hi all,

 

I have posted about this before and got some great responses--but now my problem has become more complicated and no matter what I try it is not working out.

 

(I hope it is not against community guidelines to post again, I had asked this more complicated question in the comments of my more simple question after it had been marked as solved so I dont think anyone went to look at it) 

 

Prev post with more simple ask: https://community.powerbi.com/t5/Desktop/Show-total-decrease-over-time/m-p/951859#M456099

 

So now I was wondering how I could either edit this code from my previous ask (or create a new code).

Measure =
VAR w =
    CALCULATE ( MAX ( 'Table'[Week] ), ALLSELECTED ( 'Table'[Item] ) )
VAR i =
    SELECTEDVALUE ( 'Table'[Item] )
RETURN
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Item] = i && 'Table'[Week] > w ),
        'Table'[Qty]
    )

 

What the code currently does:

Subtracts on hand qty from total (sum of all on hand qty) as the Ship Date passes

 

Now let's make it more complicated...

 

What I now would like it to do:

If Start Date has already passed, Use as starting On-Hand qty (lets call it TOTAL qty)

Subtract on hand qty from TOTAL as Ship Date passes

Add on hand qty to TOTAL as Start Date passes

 

Here is a simple example that I made in excel to visually show what I mean:

Capture.PNG

https://drive.google.com/file/d/1e--PjJHbpJbuYFDvaU2c-NmMRicrf29o/view?usp=sharing

^google drive link for the excel file so you can see it better 

 

 

Is this possible? Are we trying to be too ambitious with this? Any help will be much appreicated ❤️ 

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @sy898661 

How do you define [current day], I assume it is a spearate measure.

Then add a spearate dim week bin table

now try this measure logic:

Measure = 
VAR i =
    SELECTEDVALUE ( 'Table'[Item Number] )
RETURN
    IF (
        [current day] > MAX ( 'week Bin'[Ship Week bin] ),
        CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Planned Start Date] <= [current day]
                    && 'Table'[Item Number] = i
            )
        ),
        CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Planned Start Date] <= MAX ( 'week Bin'[Ship Week bin] )+6
                    && 'Table'[Item Number] = i
            )
        )
    )
        - CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Ship Week bin] <= MAX ( 'week Bin'[Ship Week bin] )
                    && 'Table'[Item Number] = i
            )
        )

Result:
8.JPG

 

Regards,

Lin

Community Support Team _ Lin
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
sy898661
Helper V
Helper V

Ahhh thank you both so much!!!! I cannot tell you how awesome this is! @v-lili6-msft @AiolosZhao 

v-lili6-msft
Community Support
Community Support

hi  @sy898661 

How do you define [current day], I assume it is a spearate measure.

Then add a spearate dim week bin table

now try this measure logic:

Measure = 
VAR i =
    SELECTEDVALUE ( 'Table'[Item Number] )
RETURN
    IF (
        [current day] > MAX ( 'week Bin'[Ship Week bin] ),
        CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Planned Start Date] <= [current day]
                    && 'Table'[Item Number] = i
            )
        ),
        CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Planned Start Date] <= MAX ( 'week Bin'[Ship Week bin] )+6
                    && 'Table'[Item Number] = i
            )
        )
    )
        - CALCULATE (
            SUM ( 'Table'[On Hand Qty] ),
            FILTER (
                'Table',
                'Table'[Ship Week bin] <= MAX ( 'week Bin'[Ship Week bin] )
                    && 'Table'[Item Number] = i
            )
        )

Result:
8.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
AiolosZhao
Memorable Member
Memorable Member

Hi @sy898661 ,

 

Hope the chart in the below screenshot is what you want:

rolling inventory over time.PNG

 

1. I created a new table with one column to be the axis in the chart.

Table 2 = SELECTCOLUMNS('Table (6)',"New WEEK BIN",'Table (6)'[Ship Week bin])

2. Then I created a new measure in the new table to be the values in the chart.

Measure 5 = CALCULATE(SUM('Table (6)'[On Hand Qty]),FILTER('Table (6)',AND(WEEKNUM('Table (6)'[Planned Start Date]) <= WEEKNUM(MAX('Table 2'[New WEEK BIN])),WEEKNUM('Table (6)'[Ship Date]) > WEEKNUM(MAX('Table 2'[New WEEK BIN])))))

  

Please try.

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.