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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

opening stock

LastDateInPreviousMonth =
VAR SelectedDate = MAX('TT sellout 2023 to date'[Date])
VAR PreviousMonthStartDate = EOMONTH(SelectedDate, -2) + 1
VAR PreviousMonthEndDate = EOMONTH(SelectedDate, -1)

RETURN
    CALCULATE(
        MAX('TT sellout 2023 to date'[Date]),
        FILTER(
            ALL('TT sellout 2023 to date'),  -- Use ALL to ensure all data is considered
            'TT sellout 2023 to date'[Date] >= PreviousMonthStartDate &&
            'TT sellout 2023 to date'[Date] <= PreviousMonthEndDate
        )
    )




Opening Stock Previous Month =
VAR LastDateInPrevMonth = [LastDateInPreviousMonth]

RETURN
    CALCULATE(
        SUM('TT sellout 2023 to date'[Inventory in Cases]),
        FILTER(
            ALLSELECTED('TT sellout 2023 to date'),
            'TT sellout 2023 to date'[Date] = LastDateInPrevMonth
        )
    )
 
i have this two measures that check the last date of each prevoius month for inventory in cases and displays the sum as the opening stock. the problem comes in when i select one month on the slicer it shows the data as blank but if i choose multiple months for example Jan to may it shows the correct data. Does anyone know how to solve this?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

 

You might consider using the SELECTEDVALUE() function to get the specific product or a specific category:

Opening Stock Previous Month =
VAR LastDateInPrevMonth = [LastDateInPreviousMonth]
VAR SelectProduct=SELECTEDVALUE('TT sellout 2023 to date'[Product])
VAR SelectCategory=SELECTEDVALUE('TT sellout 2023 to date'[category])
RETURN
    CALCULATE(
        SUM('TT sellout 2023 to date'[Inventory in Cases]),
        FILTER(
            ALL('TT sellout 2023 to date'),
            'TT sellout 2023 to date'[Date] = LastDateInPrevMonth&&
            'TT sellout 2023 to date'[Product]=SelectProduct &&
            'TT sellout 2023 to date'[category]=SelectCategory
        )
    )

 

Best Regards,

Liu Yang

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

4 REPLIES 4
Anonymous
Not applicable

Hi  @Anonymous ,

 

You might consider using the SELECTEDVALUE() function to get the specific product or a specific category:

Opening Stock Previous Month =
VAR LastDateInPrevMonth = [LastDateInPreviousMonth]
VAR SelectProduct=SELECTEDVALUE('TT sellout 2023 to date'[Product])
VAR SelectCategory=SELECTEDVALUE('TT sellout 2023 to date'[category])
RETURN
    CALCULATE(
        SUM('TT sellout 2023 to date'[Inventory in Cases]),
        FILTER(
            ALL('TT sellout 2023 to date'),
            'TT sellout 2023 to date'[Date] = LastDateInPrevMonth&&
            'TT sellout 2023 to date'[Product]=SelectProduct &&
            'TT sellout 2023 to date'[category]=SelectCategory
        )
    )

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

Thanks for the reply from lbendlin , please allow me to provide another insight: 
Hi  @Anonymous ,

You can change ALLSELECTED() to All() for that formula:

Opening Stock Previous Month =
VAR LastDateInPrevMonth = [LastDateInPreviousMonth]
RETURN
    CALCULATE(
        SUM('TT sellout 2023 to date'[Inventory in Cases]),
        FILTER(
            ALL('TT sellout 2023 to date'),
            'TT sellout 2023 to date'[Date] = LastDateInPrevMonth
        )
    )

vyangliumsft_0-1726040912648.png

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

Thanks Liu, i had tried that and it works. the issue it that i would like for other slicers to affect it but it doesn't work. for example if i want to view stock for a specific product or a specific category, the slicers do not affect it at all.

lbendlin
Super User
Super User

Your slicer must be fed from a disconnected table.

Helpful resources

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