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

Count most recent and consecutive streak of values IF values are <1

Hi everyone,

I'm trying to make a measure that: counts how many times a Product has a Value below 1,0. The count has to take into account that it is consecutive, but also counts down from the most recent week.

In my example below:
- Product A should get a measure count of 0 (because the most recent week, W3, has a value of above 1,0)
- Product B should get a measure count of 2 (because the most recent two weeks are below 1,0).

ProductWeekValue
AW10,9
AW20,9
AW31,1

B

W11,0
BW20,9
BW30,9


I hope someone has an idea on how to make this work. I could not find anything that tackled the 'most recent week' part of the question unfortunately.

 

Thanks in advance for taking the time and effort 🙂

1 ACCEPTED SOLUTION

hi @Anonymous 

try like:

Count = 
VAR _maxweek = MAX(TableName[Week2])
VAR _week = 
MAXX(
    FILTER(
        TableName,
        TableName[Value]>=1||TableName[Value]=BLANK()
    ),
    TableName[Week2]
)
RETURN
_maxweek - _week

 

FreemanZ_0-1677158856143.png

 

View solution in original post

10 REPLIES 10
FreemanZ
Super User
Super User

hi @Anonymous 

try to

1) add a calculated column with:

Week2 = SUBSTITUTE([Week],"W", "")

(It is better if you can do it in Power Query Editor)

2) write a measure like:

Count = 
VAR _maxweek = MAX(TableName[Week2])
VAR _week = 
MAXX(
    FILTER(
        TableName,
        TableName[Value]>=1
    ),
    TableName[Week2]
)
RETURN
_maxweek - _week

 

it worked like:

FreemanZ_0-1677145923549.png

 


 

Anonymous
Not applicable

Hi FreemanZ,

Your solution is working, but my dataset has made it a bit more complicated. 
I also have Products that dont have any values, so they are blank. This messes up the count measure you have written. The measure now also counts the blanks.

What would I need to alter in the measure to keep it from counting blanks as <1,0?


Thanks for your help! Happy with the current result either way 🙂

hi @Anonymous 

it may still work. Try and let us know.

Anonymous
Not applicable

Hi FreemanZ,

Unfortunately, the ones that have only blanks are the one with get a count of 52 (52weeks).
It works great for the other ones though, as you can see from my screenshot below.

FVP_0-1677148092705.png

So I need something like a COUNTA that ignore blank, but Im not sure how I would fix this in this measure. Would you know this perhaps?

 

hi @Anonymous 

could you expand your sample data and let us have a try?

Anonymous
Not applicable

Hi FreemanZ,

Thanks for taking the time to help me.

You measure works good for capturing 0 for Product A and 2 for Product B.

 

Two new examples added:
Product C in the example below would get a 3, but should get a 0 instead (edit: or maybe preferably, blank. But 0 is fine too).
Product D works good. It records a 0

 

ProductWeekValue
AW10,9
AW20,9
AW31,1

B

W11,0
BW20,9
BW30,9
CW1 
CW2 
CW3 
DW10,9
DW2 
DW31,1

hi @Anonymous 

try like:

Count = 
VAR _maxweek = MAX(TableName[Week2])
VAR _week = 
MAXX(
    FILTER(
        TableName,
        TableName[Value]>=1||TableName[Value]=BLANK()
    ),
    TableName[Week2]
)
RETURN
_maxweek - _week

 

FreemanZ_0-1677158856143.png

 

Hi @FreemanZ - I need to do something similar and was hoping to use your solution. .. but my count comes up as zero's. Any ideas would be appreciated. Thanks, John

 

JohnD61_0-1680459569887.png

 

Anonymous
Not applicable

Hi,

I know I've accepted the solution, but I was hoping you might know a quick fix for the following.

 


Whenever I add a slicer, to filter on only a specific number of weeks, measure cant cope with it.

When I set a slicer for only W2 and W3, for example.

Is there a quick fix in the measure for this? I've tried multiple things but couldnt work it out im afraid. It's driving me nuts!

ProductWeekValue
AW10,9
AW20,9
AW31,1

B

W11,0
BW20,9
BW30,9
CW1 
CW2 
CW3 
DW10,9
DW2 
DW31,1
Anonymous
Not applicable

Hi FreemanZ,

That did the trick! It returns the right value in all my testrows 🙂
Thank you for your patience and time!



Helpful resources

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

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.