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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Calculated column which counts how many times the value appears in the table for the last 30 days

Hello,

 

I have an inventory table with 2 columns, product_id and date.

Each product_id only has a date for the days we had it in stock.

Im trying to to count how many days we had the product in stock for the last 30 days before the date in the column, and i want this for all the past dates, ie check fro mthat date 30 days back how many entries it has.

 
1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Anonymous 

 

Column = 
VAR _current_product = 'Table'[product_id]
VAR _current_date = 'Table'[date]
VAR _result =
    COUNTROWS(
        FILTER(
            'Table'
            ,'Table'[product_id] = _current_product
                && 'Table'[date] >= _current_date - 29
                    && 'Table'[date] <= _current_date
        )
    )
RETURN
    _result

 


2022-05-09 22_36_04-Power BI Workspace Datasets License Permissions - Microsoft Power BI Community.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png  SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

3 REPLIES 3
SpartaBI
Community Champion
Community Champion

@Anonymous 

 

Column = 
VAR _current_product = 'Table'[product_id]
VAR _current_date = 'Table'[date]
VAR _result =
    COUNTROWS(
        FILTER(
            'Table'
            ,'Table'[product_id] = _current_product
                && 'Table'[date] >= _current_date - 29
                    && 'Table'[date] <= _current_date
        )
    )
RETURN
    _result

 


2022-05-09 22_36_04-Power BI Workspace Datasets License Permissions - Microsoft Power BI Community.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png  SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Anonymous
Not applicable

Flawless solution, thank you so much!

@Anonymous my pleasure 🙂

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.