Forum Discussion

PBI5851's avatar
PBI5851
Helper V
3 years ago
Solved

Capture average based on slicer

Hello folks, 

please can you help me figure out on how to capture the average days a member has acted based on the ActDate slicer. So when the slicer has the dates, i need to capture the latest row for the PerID within that range and capture the Actdays( no need to sum the previous rows)

ex:

IDPerIDActDateActdays
1A1231/1/20231
2A1231/2/20232
3A1231/3/20233
4A1231/4/20234
5A1231/5/20235
6A1231/6/20236
7A1231/7/20237
8A1231/8/20238
9B1231/6/20231
10B1231/7/20232
11B1231/8/20233
12B1231/9/20234
13C1231/5/20231
14C1231/6/20232
15C1231/7/20233
16C1231/8/20234
17C1231/9/20235
18C1231/10/20236
19C1231/11/20237
20C1231/12/20238

 

So when the slicer is from 1/1/23 to 1/10/23,

the total members are 3

and total actdays are 18 

- A123 @ 8, B123 @ 4 and C123 @6 

This results in an average of 6

 

 

So when the slicer is from 1/4/23 to 1/7/23,

the total members are 3

and total actdays are 12

- A123 @ 7, B123 @ 2 and C123 @ 3 

This results in an average of 3

 

 

So when the slicer is from 1/10/23 to 1/12/23,

the total members are 1

and total actdays are 8

- A123 - 0, B123 -0 and C123 - 8 

This results in an average of 8

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    Count members: = 
    COUNTROWS( SUMMARIZE( Data, PerID[PerID]))
    Actdays: = 
    VAR _lastdatecalendar =
        MAX ( 'Calendar'[Date] )
    VAR _lastdateactdate =
        MAXX (
            FILTER (
                ALLSELECTED ( Data ),
                Data[PerID] = MAX ( PerID[PerID] )
                    && Data[ActDate] <= _lastdatecalendar
            ),
            Data[ActDate]
        )
    RETURN
        IF (
            HASONEVALUE ( PerID[PerID] ),
            CALCULATE ( SUM ( Data[Actdays] ), 'Calendar'[Date] = _lastdateactdate )
        )
    Total actdays: = 
    SUMX( VALUES( PerID[PerID]), [Actdays:] )
    Average actdays: = 
    AVERAGEX( VALUES( PerID[PerID]), [Actdays:] )

     

2 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    Count members: = 
    COUNTROWS( SUMMARIZE( Data, PerID[PerID]))
    Actdays: = 
    VAR _lastdatecalendar =
        MAX ( 'Calendar'[Date] )
    VAR _lastdateactdate =
        MAXX (
            FILTER (
                ALLSELECTED ( Data ),
                Data[PerID] = MAX ( PerID[PerID] )
                    && Data[ActDate] <= _lastdatecalendar
            ),
            Data[ActDate]
        )
    RETURN
        IF (
            HASONEVALUE ( PerID[PerID] ),
            CALCULATE ( SUM ( Data[Actdays] ), 'Calendar'[Date] = _lastdateactdate )
        )
    Total actdays: = 
    SUMX( VALUES( PerID[PerID]), [Actdays:] )
    Average actdays: = 
    AVERAGEX( VALUES( PerID[PerID]), [Actdays:] )