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
Lucianovaz
Frequent Visitor

Count id based Max Date and status

Friends, SAVE ME!!!HELP!!! COUNT MAX DATE with criteria.

In a data slicer (year), knowing what was the last status of id_voluntario, if it is "AND" count, but I can't solve it.
My table: tb_volunteers

Where these volunteers come in and out all the time and each time he enters he enters a log line and the status changes to "E",
but the input_date remains the first, and writes update_date at that moment, when he exits he inserts a new log line status changes "Y" and writes the update_date.
Volunteer_id,birth_date, entry_date, status,update_date.
I need to count dynamically according to the movement of the data slicer.
And also average age of these volunteers until the data slicer date.
Also know the average age of the counted volunteers.Screenshot_20220726-131103_Excel.jpg

1 ACCEPTED SOLUTION

Hi @Lucianovaz ,

 

You need create an  independent date table for slicer. Then create some smilier measures like the following to calculate.

 

[if], put this measure in filter pane of table visual to display the last status of id_voluntario and set it show items when is 1.

if =
VAR _selected_date =
    MAX ( 'calendar'[Date] )
VAR _topn =
    TOPN (
        1,
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Id_voluntario] = SELECTEDVALUE ( 'Table'[Id_voluntario] )
                && [data_atulizacao] <= _selected_date
        ),
        [data_atulizacao], DESC
    )
VAR _status_date =
    MAXX ( _topn, [data_atulizacao] )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[data_atulizacao] ) = _status_date, 1 )

Result:

vchenwuzmsft_0-1659088004258.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

2 REPLIES 2
Lucianovaz
Frequent Visitor

In short, I need to filter the last dates of each volunteer and count if the status is "E" 
and also calculate the age of this volunteer until the selected year or month.
for example if
select the year 2008 the id A101 is inactive because the last date was 05/10/2005 and the status ="S".
already if you select 2020 the same id A101 is with status="E"
Already the id A109 is active because the last date was 03/12/2009 and status ="E".

Hi @Lucianovaz ,

 

You need create an  independent date table for slicer. Then create some smilier measures like the following to calculate.

 

[if], put this measure in filter pane of table visual to display the last status of id_voluntario and set it show items when is 1.

if =
VAR _selected_date =
    MAX ( 'calendar'[Date] )
VAR _topn =
    TOPN (
        1,
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Id_voluntario] = SELECTEDVALUE ( 'Table'[Id_voluntario] )
                && [data_atulizacao] <= _selected_date
        ),
        [data_atulizacao], DESC
    )
VAR _status_date =
    MAXX ( _topn, [data_atulizacao] )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[data_atulizacao] ) = _status_date, 1 )

Result:

vchenwuzmsft_0-1659088004258.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the 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.