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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count the most recent and consecutive values below 1

Hi all,

I'm struggling to find a working solution in powerbi for the following. I've got a dataset that's look like the one in the table below. 
I want to make a measure that counts how many times a product scores below 1,00 consecutively from the most recent available week selected.

For example: If I select all three weeks (column: Week nr), Milk should get a Desired value of 2, because it has been below 1,00 in the 2 most recent weeks.

 

ProductWeek nrValueDesired value
Milk2022_WK 52   1,000
Milk2023_WK 01   0,901
Milk2023_WK 02   0,952
Bread2022_WK 52   0,851
Bread2023_WK 01   0,902
Bread2023_WK 02   1,000
Juice2022_WK 52   1,000
Juice2023_WK 01   0,901
Juice2023_WK 02   1,000

 

Would anyone have an idea on how to tackle this problem? 
Any advice would be appreciated! Thanks for taking the time to read this 🙂

 

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1679419353332.png

 

 

 

Desired result measure: =
VAR _newtable =
    ADDCOLUMNS (
        FILTER ( ALL ( Data ), Data[Product] = MAX ( Data[Product] ) ),
        "@index", IF ( Data[Value] >= 1, 1, 0 )
    )
VAR _groupingtable =
    ADDCOLUMNS (
        _newtable,
        "@group",
            SUMX (
                FILTER ( _newtable, Data[Week nr] <= EARLIER ( Data[Week nr] ) ),
                [@index]
            )
    )
RETURN
    IF (
        HASONEVALUE ( Data[Product] ),
        IF (
            MAX ( Data[Value] ) >= 1,
            0,
            COUNTROWS (
                FILTER (
                    _groupingtable,
                    [@index] <> 1
                        && Data[Week nr] <= MAX ( Data[Week nr] )
                )
            )
        )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi Jihwan_Kim,

Thank you for taking the time to reply! You understood the question perfectly, but im afraid it did not work.

 

I want to share a sample of my actual dataset so you can see the result, but the forum wont allow me to upload the pbix file. How did you do this? 

Hi,

Thank you for your message, and you can use Onedrive, googledrive, or Dropbox (or any other method) to share the link of the pbix file.
Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi,

thanks for the tip. Im probably to new of a user to upload directly here.

I have created a dropbox link.
https://www.dropbox.com/t/d5kxUtQwA9IBXPDp

 

So basically, the data is the same, but expanded with multiple week numbers, and one extra variable (concurrent, which means competitor).

I didnt think both of these would interfere with your written solution, but apparantly it does. sorry for that

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.