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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Wayne74
Helper I
Helper I

Working out Days since based on a flag

The logic for this one has me stumped and I am hoping the super brain collective may be able to help me.  I have been using Power BI on and off for quite a while, but still have a long way to go and a lot to learn.

 

Ok so I have a data source that is prestart checks for vehicles.  I have thousands of these across around 100 vehicles.  I want to be able to present the Registration number, Issue and Days since first reported for each vehicle that currently has an issue.  

 

Here is a dirty sample I created.  In this example I would want to show Rego 123abc, Issue 1, DATEDIFF(today, 18/03/2024).  

Wayne74_0-1717130472755.png

If it was only one vehicle I could easily sort by date (descending) and then find the first entry where Issue 1 = false.  However there are a lot of vehicles so it needs to be more dynamic.

 

I am sure some of you have hit similiar issues and I just need a nudge in the right direction on how to accomplish this please.

 

Thank you,

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @Wayne74, I'm not sure if this is what are you looking for:

 

Before

dufoq3_0-1717147019399.png

 

After

dufoq3_1-1717147034154.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMkxU0lEyNtA3MNY3MjAyAXJCgkJdlWJ1oFJGlrilcOsytECScnP0CUaWM8cjh9tIU6y6jJKgukwxdIGlLHDKGCPJoJuHoSkWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RegNo = _t, Date = _t, #"Issue 1" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Issue 1", type logical}}),
    GroupedRows = Table.Group(ChangedType, {"RegNo"}, {{"Days since last FALSE ISSUE", each 
        [ a = List.Max(Table.SelectRows(_, (x)=> x[#"Issue 1"] = false)[Date]), //Max FALSE Date
          b = Duration.TotalDays(Date.From(DateTime.FixedLocalNow()) - a)
        ][b], Int64.Type}})
in
    GroupedRows

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
Wayne74
Helper I
Helper I

That will help a lot.  Thank you very much

You're welcome.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

dufoq3
Super User
Super User

Hi @Wayne74, I'm not sure if this is what are you looking for:

 

Before

dufoq3_0-1717147019399.png

 

After

dufoq3_1-1717147034154.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMkxU0lEyNtA3MNY3MjAyAXJCgkJdlWJ1oFJGlrilcOsytECScnP0CUaWM8cjh9tIU6y6jJKgukwxdIGlLHDKGCPJoJuHoSkWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RegNo = _t, Date = _t, #"Issue 1" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Issue 1", type logical}}),
    GroupedRows = Table.Group(ChangedType, {"RegNo"}, {{"Days since last FALSE ISSUE", each 
        [ a = List.Max(Table.SelectRows(_, (x)=> x[#"Issue 1"] = false)[Date]), //Max FALSE Date
          b = Duration.TotalDays(Date.From(DateTime.FixedLocalNow()) - a)
        ][b], Int64.Type}})
in
    GroupedRows

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.

Top Solution Authors