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
jdecoste
New Member

How do you to get accurate daily status counts for table that only logs changes?

vinvehicle_fleet_statusvehicle_uptime_statusrecord_date
1G1FW6S00H4188325In fleetUptime4/26/22 0:38
1G1FW6S03H4146523In fleetUptime4/26/22 17:10
1G1FX6S00H4146123In fleetUptime4/27/22 22:39
1G1FW6S07H4183654In fleetDowntime4/27/22 22:39
1G1FW6S00H4187235In fleetDowntime4/27/22 22:39
1G1FZ6S05K4134756In fleetUptime4/28/22 17:25
1G1FW6S09H4181765In fleetUptime4/28/22 18:42
1G1FX6S00J4114944In fleetDowntime4/28/22 19:40
1G1FX6S00J4114054In fleetDowntime4/28/22 23:16

 

So I have a table set up like so, that logs a vehicles status. When a status changes (ie. uptime to downtime) a new row is inserted with the change reflected and the time. I am trying to get an output table that get and aggregate count of each status by day, which will look something like this.

DateIn fleetUptime
1/1/227671
1/2/227775
1/3/2277

74

 

So far, I have created a measure that will count a status:

count_in_fleet = CALCULATE(COUNTROWS(vehicle_logs),vehicle_logs[vehicle_fleet_status] = "In fleet")

 

And a summary table that shows that by day:

vehicle_log_aggregate =

SUMMARIZE(vehicle_logs,vehicle_logs[record_date].[Date],
"In Fleet", vehicle_logs[count_in_fleet])

 

However, since a status may not change over one day, the counts are innacurate. I need to somehow calculate what a VIN's status will be on x date by looking at the max(status) <= x date. However, I cant figure out how to put this together. Any help is greatly appreciated!

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @jdecoste,

You can take a look at the following calculated table expression to create a new table with aggregated records:

Table2 =
VAR summary =
    FILTER (
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Date],
            [vin],
            "Infleet",
                COUNTX (
                    FILTER ( ALLSELECTED ( 'Table' ), [Date] = EARLIER ( 'Table'[Date] ) ),
                    [vin]
                ),
            "Status Changed", COUNTROWS ( VALUES ( 'Table'[vehicle_uptime_status] ) )
        ),
        [Status Changed] >= 2
    )
RETURN
    DISTINCT (
        SELECTCOLUMNS (
            summary,
            "Date", [Date],
            "Infleet", [Infleet],
            "Status Changed", [Status Changed]
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @jdecoste,

You can take a look at the following calculated table expression to create a new table with aggregated records:

Table2 =
VAR summary =
    FILTER (
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Date],
            [vin],
            "Infleet",
                COUNTX (
                    FILTER ( ALLSELECTED ( 'Table' ), [Date] = EARLIER ( 'Table'[Date] ) ),
                    [vin]
                ),
            "Status Changed", COUNTROWS ( VALUES ( 'Table'[vehicle_uptime_status] ) )
        ),
        [Status Changed] >= 2
    )
RETURN
    DISTINCT (
        SELECTCOLUMNS (
            summary,
            "Date", [Date],
            "Infleet", [Infleet],
            "Status Changed", [Status Changed]
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.