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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Júlio
Frequent Visitor

Help on count amount of days that each car is in the same status

I want to count the number of days that each plat is in the same status.

 

Date Plate Status
15/fev ABC1111 Manutenção
14/fev ABC1111 Manutenção
13/fev ABC1111 Manutenção
12/fev ABC1111 Manutenção
11/fev ABC1111 Em Preparação
10/fev ABC1111 Em Preparação
09/fev ABC1111 Manutenção
08/fev ABC1111 Manutenção
07/fev ABC1111 Manutenção
06/fev ABC1111 Em Preparação
05/fev ABC1111
04/fev ABC1111
03/fev ABC1111
02/fev ABC1111
01/fev ABC1111
15/fev ABC2222 Em Preparação
14/fev ABC2222 Em Preparação
13/fev ABC2222 Em Preparação
12/fev ABC2222 Em Preparação
11/fev ABC2222 Em Preparação
10/fev ABC2222 Em Preparação
09/fev ABC2222 Em Preparação
08/fev ABC2222 Em Preparação
07/fev ABC2222 Em Preparação
06/fev ABC2222 Em Preparação
05/fev ABC2222 Em Preparação
04/fev ABC2222 Em Preparação
03/fev ABC2222 Em Preparação
02/fev ABC2222 Em Preparação
01/fev ABC2222 Em Preparação
15/fev ABC3333 Manutenção
14/fev ABC3333 Em Preparação
13/fev ABC3333 Em Preparação
12/fev ABC3333 Em Preparação
11/fev ABC3333 Em Preparação
10/fev ABC3333 Em Preparação
09/fev ABC3333 Em Preparação
08/fev ABC3333 Em Preparação
07/fev ABC3333 Em Preparação
06/fev ABC3333 Em Preparação
05/fev ABC3333 Em Preparação
04/fev ABC3333 Em Preparação
03/fev ABC3333 Em Preparação
02/fev ABC3333 Em Preparação
01/fev ABC3333 Em Preparação


Result: ABC1111 - Manutenção - 4 days
ABC2222- Em Preparação - 15 days
ABC3333 - Manutenção - 1 day

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Júlio ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1676960155426.png

2. create measure with below dax formula

Last Status =
VAR cur_plate =
    SELECTEDVALUE ( 'Table'[Plate] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [Plate] = cur_plate )
VAR max_date =
    MAXX ( tmp, [Date] )
VAR tmp1 =
    FILTER ( ALL ( 'Table' ), [Date] = max_date && [Plate] = cur_plate )
RETURN
    CALCULATE ( MAX ( [Status] ), tmp1 )
Days =
VAR cur_status = [Last Status]
VAR cur_plate =
    SELECTEDVALUE ( 'Table'[Plate] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [Status] = cur_status && [Plate] = cur_plate )
RETURN
    COUNTROWS ( tmp )

3. add a table visual with field and mesure

vbinbinyumsft_1-1676960260512.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Júlio ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1676960155426.png

2. create measure with below dax formula

Last Status =
VAR cur_plate =
    SELECTEDVALUE ( 'Table'[Plate] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [Plate] = cur_plate )
VAR max_date =
    MAXX ( tmp, [Date] )
VAR tmp1 =
    FILTER ( ALL ( 'Table' ), [Date] = max_date && [Plate] = cur_plate )
RETURN
    CALCULATE ( MAX ( [Status] ), tmp1 )
Days =
VAR cur_status = [Last Status]
VAR cur_plate =
    SELECTEDVALUE ( 'Table'[Plate] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [Status] = cur_status && [Plate] = cur_plate )
RETURN
    COUNTROWS ( tmp )

3. add a table visual with field and mesure

vbinbinyumsft_1-1676960260512.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FreemanZ
Super User
Super User

hi @Júlio 

 

you can just plot a table visual with all three column. 

ensure you choose count for the date column.

 

it worked like this:

FreemanZ_0-1676472741936.png

 

That's exactaly my problem.
As you can see the result for the plate ABC1111 on the status of "Manutenção" is 7.

But i wanna know how many days is on the same status, so the correct result is 4.

I don't wanna count the total, only the last status of each plate.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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