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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ausphil
Helper I
Helper I

Return time of first non-zero value on column

Hello all,

 

I have a table with columns Time, Index, Shift and Value like so:

 

TimeIndexShiftValue
7:001Day0
8:002Day32
9:003Day34
10:004Day68
11:005Day72
12:006Day0
13:007Day35
14:008Day40
15:009Day50
16:0010Day60
17:0011Day10
18:0012Day0
19:0013Night0
20:0014Night0
21:0015Night0
22:0016Night70
23:0017Night60
0:0018Night50
1:0019Night70
2:0020Night0
3:0021Night80
4:0022Night0
5:0023Night0
6:0024Night0

 

I need to write some measures to return the red highlighted values like so:

1. The time of the first non-zero value where shift = day (8:00)

2. The time of the first continuous zero value through to the end of the shift where shift = day (18:00)

3. The time of the first non-zero value where shift = night (22:00)

4. The time of the first continuous zero value through to the end of the shift where shift = night (4:00)

 

Appreciate the help!

 

Thank you.

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @ausphil 

 

Try this for your 4th requirement i,e. The time of the first continuous zero value through to the end of the shift where shift = night (4:00).

 

You can use same logic for 2nd requirement

 

Measure4 =
VAR LastNonZeroNight =
    MAXX (
        TOPN ( 1, FILTER ( Table1, [Shift] = "Night" && [Value] <> 0 ), [Index], DESC ),
        [Index]
    )
RETURN
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Shift] = "Night"
                    && [Value] = 0
                    && [Index] > LastNonZeroNight
            ),
            [Index], ASC
        ),
        [Time]
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

@ausphil 

 

For first and third requirment, you could try this MEASURE's pattern

 

Measure 1 =
MINX (
    TOPN ( 1, FILTER ( Table1, [Shift] = "Day" && [Value] <> 0 ), [Index], ASC ),
    [Time]
)

 


Regards
Zubair

Please try my custom visuals


@Zubair_Muhammad wrote:

@ausphil 

 

For first and third requirment, you could try this MEASURE's pattern

 

Measure 1 =
MINX (
    TOPN ( 1, FILTER ( Table1, [Shift] = "Day" && [Value] <> 0 ), [Index], ASC ),
    [Time]
)

 


Thank you @Zubair_Muhammad this one works perfectly!

@ausphil 

 

 

Just change day to night or vice versa for similar 2nd and 3rd MEASURE


Regards
Zubair

Please try my custom visuals
Zubair_Muhammad
Community Champion
Community Champion

Hi @ausphil 

 

Try this for your 4th requirement i,e. The time of the first continuous zero value through to the end of the shift where shift = night (4:00).

 

You can use same logic for 2nd requirement

 

Measure4 =
VAR LastNonZeroNight =
    MAXX (
        TOPN ( 1, FILTER ( Table1, [Shift] = "Night" && [Value] <> 0 ), [Index], DESC ),
        [Index]
    )
RETURN
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Shift] = "Night"
                    && [Value] = 0
                    && [Index] > LastNonZeroNight
            ),
            [Index], ASC
        ),
        [Time]
    )

Regards
Zubair

Please try my custom visuals


@Zubair_Muhammad wrote:

Hi @ausphil 

 

Try this for your 4th requirement i,e. The time of the first continuous zero value through to the end of the shift where shift = night (4:00).

 

You can use same logic for 2nd requirement

 

Measure4 =
VAR LastNonZeroNight =
    MAXX (
        TOPN ( 1, FILTER ( Table1, [Shift] = "Night" && [Value] <> 0 ), [Index], DESC ),
        [Index]
    )
RETURN
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Shift] = "Night"
                    && [Value] = 0
                    && [Index] > LastNonZeroNight
            ),
            [Index], ASC
        ),
        [Time]
    )

Thank you @Zubair_Muhammad this seems to work for the 4th requirement, but for the 1st requirement it is returning 7:00 AM. Any thoughts?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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