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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MGinGermany
Frequent Visitor

Identifying the first occurance of a value and restarting the count when there is a value inbetween

Hello and thank you in advance!

I am trying to add a column in powerBI that would identify the first occurance of a value and then reidentify the same value when it comes back into the list. I think its easier explained with a data example:

 

TimeValueDesired Column
05/14/2024 1:00:00

1

1

05/14/2024 2:00:001 
05/14/2024 3:00:002 
05/14/2024 4:00:003 
05/14/2024 5:00:0011
05/14/2024 6:00:001 
05/14/2024 7:00:001 
05/14/2024 8:00:002 
05/14/2024 9:00:003 
05/14/2024 10:00:0011
05/14/2024 11:00:002 
05/14/2024 12:00:003 
05/14/2024 13:00:0011
05/14/2024 14:00:00

1

 

05/14/2024 15:00:002 
05/14/2024 16:00:0011
05/14/2024 17:00:001 
05/14/2024 18:00:004 
05/14/2024 19:00:005 
05/14/2024 20:00:006 
05/14/2024 21:00:0011
05/14/2024 22:00:001 
05/14/2024 23:00:003 
05/15/2024 00:00:0011
05/15/2024 01:00:001 
05/16/2024 02:00:002 

The data is actually every 15 minutes, but I can remove duplicates up to the nearest hour already. Is there some way to add this column? I have tried to utilize COUNTROWS, EARLIER, DISTINCTCOUNT,  etc, but it either adds too many 1s or doesnt count after the first 1. 

It essentially needs to start looking for the next 1, and then ignore any that come consecutevely afterwards. 

Thanks again for the help!

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @MGinGermany,

If you want to do it via DAX, here is an option:

barritown_0-1715720369959.png

In plain text:

Flag = 
VAR triggerValue = 1
VAR currentTime = [Time]
VAR previousTime = MAXX ( FILTER ( Data, [Time] < currentTime ), [Time] )
VAR previousValue = MINX ( FILTER ( Data, [Time] = previousTime ), [Value] )
RETURN IF ( previousValue <> triggerValue && [Value] = triggerValue, 1 )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

2 REPLIES 2
barritown
Super User
Super User

Hi @MGinGermany,

If you want to do it via DAX, here is an option:

barritown_0-1715720369959.png

In plain text:

Flag = 
VAR triggerValue = 1
VAR currentTime = [Time]
VAR previousTime = MAXX ( FILTER ( Data, [Time] < currentTime ), [Time] )
VAR previousValue = MINX ( FILTER ( Data, [Time] = previousTime ), [Value] )
RETURN IF ( previousValue <> triggerValue && [Value] = triggerValue, 1 )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

thanks, that worked perfectly!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.