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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Unexperienced in DAX

Hi,

 

Data

I have a dataset in which different units (unit_id's) get an update every 10 minutes. There are multiple columns under which a datetime column, a idle_time column and unit_id column. 

 

Necessary

I need just the rows in which the next value of idle_time is 0 (per unit).

So for example from unit 1&2:

 

unit_iddatetimeidle_time
11-5-2021 10:10    53
11-5-2021 10:20    63
21-5-2021 10:23    12
11-5-2021 10:30     0
21-5-2021 10:33    22
21-5-2021 10:43     0

 

I now just need the bold rows (the peeks per unit). All updates and al units are in the same table. How can i filter the rows out for every unit, where the next idle_time value is 0? So it's based on the date-time increasing.

 

Thanks!

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

Solution in Power Query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcuxDcAgDETRVZBrkHx3IUVWQey/Blh0xO1/+mMYrBpab3SiwD/4Dl02698Y9h7jbYrA9FN8nm6KjUzt0dnmAg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [unit_id = _t, datetime = _t, idle_time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"unit_id", Int64.Type}, {"datetime", type datetime}, {"idle_time", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"unit_id"}, {{"ar", each let index = Table.AddIndexColumn(_, "index", 0), pos = List.Transform(List.PositionOf([idle_time], 0, Occurrence.All), each _-1) in Table.SelectRows(index, each List.Contains(pos, [index]))}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"datetime", "idle_time"}, {"datetime", "idle_time"})
in
    #"Expanded ar"

Screenshot 2021-06-04 153537.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

AlB
Community Champion
Community Champion

Hi @Anonymous 

This can probebly best be done in PQ

If you want it in DAX, xreate a new calculated table:

NewTable = 
FILTER (
    Table1,
    VAR zeroTime_ =
        CALCULATE (
            MAX ( Table1[datetime] ),
            Table1[idle_time] = 0,
            ALLEXCEPT ( Table1, Table1[unit_id] )
        )
    VAR previous_ =
        CALCULATE (
            MAX ( Table1[datetime] ),
            Table1[datetime] < zeroTime_,
            ALLEXCEPT ( Table1, Table1[unit_id] )
        )
    RETURN
        previous_ = Table1[datetime]
)

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

amitchandak
Super User
Super User

@Anonymous , create a new flag column like


new column =
var _max = minx(filter(Table, [unit_id] =earlier([unit_id]) && [datetime]> earlier([datetime])),[datetime])
return
if(minx(filter(Table, [unit_id] =earlier([unit_id]) && [datetime]= _max),[idle_time]) =0, 1, blank())

 

and use

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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