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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
feralvarez994
Helper II
Helper II

Calculate Stock certain month

Hi everyone, i have a table with cars code, buy date and sell date, seller, buyer and city, also a calendar table. The calendar table and the car table are linked by buy date

I have two filters in the page (year and month filter separately)

 

I want to calculate the stock by the month and year selected, by counting the cars that have been bought before the first day of the month/year selected and hasnt been sold OR had been sold after the same starting day of the month. Also i want to display this by seller and by city in a table to calculate the stock rotation.

 

How can a i calculate this ? Im using this measure but its not working

 

Stock autos = CALCULATE(
             COUNTROWS(AUTOS),
             FILTER(
                 'AUTOS',
                 'AUTOS'[FECHA COMPRA] <= FIRSTDATE(Calendario[Fecha])
                 && (AUTOS[Fecha Reserva] >= STARTOFMONTH(Calendario[Fecha])
                     || ISBLANK(AUTOS[Fecha Reserva]))
                 && YEAR(AUTOS[FECHA COMPRA]) = YEAR(SELECTEDVALUE(Calendario[Fecha])
                 && MONTH(AUTOS[FECHA COMPRA]) = MONTH(SELECTEDVALUE(Calendario[Fecha]))
             )
         ))
 
Filters in the page (year selected and month selected)
feralvarez994_0-1680708694704.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

Stock autos =
VAR MinDate =
    MIN ( 'Calendar'[Date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( Autos ),
        'Calendar'[Date] <= MinDate,
        Autos[Sell date] > MinDate
            || ISBLANK ( Autos[Sell date] )
    )
RETURN
    Result

You don't need to explicitly specify a filter for the buy date, the relationship with the calendar table will do that, and by specifying a filter on the date column of the calendar table that will automatically remove any filters on the calendar table from your slicers, as long as it is marked as a date table.

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

Try

Stock autos =
VAR MinDate =
    MIN ( 'Calendar'[Date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( Autos ),
        'Calendar'[Date] <= MinDate,
        Autos[Sell date] > MinDate
            || ISBLANK ( Autos[Sell date] )
    )
RETURN
    Result

You don't need to explicitly specify a filter for the buy date, the relationship with the calendar table will do that, and by specifying a filter on the date column of the calendar table that will automatically remove any filters on the calendar table from your slicers, as long as it is marked as a date table.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.