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
Anonymous
Not applicable

MEASURE CALCULATING THE AVERAGE OF ALL THE VALUES FROM MAX DATES BY MULTPLE COLUMNS

Hi Guys,

 

Newbie here,

 

Can you help me create a measure that will calculate the average of all the last values from a certain column based on a date with a group by function?

 

For example.

Highlighted in YELLOW are the values from the MAX of date column based on ACCOUNT, EMPLOYEE, and TYPE.

 

RAW TABLE

matty_a4d3_0-1631600609838.png

 

DESIRED OUTPUT:

matty_a4d3_1-1631600671051.png

 

I hope I clearly explained what am I trying to accomplish. Let me know for any questions.

 

Thank you so much for your help guys in advance.

  

2 ACCEPTED SOLUTIONS

Hi @Anonymous ,

 

First create a calculated column as below:

_check =
VAR _maxdate =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = EARLIER ( 'Table'[Account] )
                && 'Table'[Employee] = EARLIER ( 'Table'[Employee] )
                && 'Table'[Type] = EARLIER ( 'Table'[Type] )
        ),
        [Date]
    )
RETURN
    IF ( 'Table'[Date] = _maxdate, 1, BLANK () )

Then create a measure as below:

Average =
VAR _sum =
    SUMX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = MAX ( 'Table'[Account] )
                && 'Table'[Employee] = MAX ( 'Table'[Employee] )
                && 'Table'[_check] = 1
        ),
        'Table'[Value]
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Account] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = MAX ( 'Table'[Account] )
                && 'Table'[Employee] = MAX ( 'Table'[Employee] )
                && 'Table'[_check] = 1
        )
    )
RETURN
    DIVIDE ( _sum, _count )

And you will see:

vkellymsft_0-1631847330607.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my raeply as a solution!

View solution in original post

Change All Function with AllSELECTED hope it will works


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Try a measure like

 


calculate(averageX(Table, LASTNONBLANK(Table[Date], Max(Table[Value]))), filter(allselected(Table), [ACCOUNT] = max(Table[Account]) && [EMPLOYEE] = max(Table[EMPLOYEE])
&& [TYPE] = max(Table[Type])))

 

 

Anonymous
Not applicable

Hi @amitchandak ,

 

Thank you for your response. However, the result is different from what I've expected. Can you check if there is something that I did wrong?

 

Please see the screenshot below for the result of my query.

 

matty_a4d3_0-1631642235158.png

 

Hi @Anonymous ,

 

First create a calculated column as below:

_check =
VAR _maxdate =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = EARLIER ( 'Table'[Account] )
                && 'Table'[Employee] = EARLIER ( 'Table'[Employee] )
                && 'Table'[Type] = EARLIER ( 'Table'[Type] )
        ),
        [Date]
    )
RETURN
    IF ( 'Table'[Date] = _maxdate, 1, BLANK () )

Then create a measure as below:

Average =
VAR _sum =
    SUMX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = MAX ( 'Table'[Account] )
                && 'Table'[Employee] = MAX ( 'Table'[Employee] )
                && 'Table'[_check] = 1
        ),
        'Table'[Value]
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Account] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Account] = MAX ( 'Table'[Account] )
                && 'Table'[Employee] = MAX ( 'Table'[Employee] )
                && 'Table'[_check] = 1
        )
    )
RETURN
    DIVIDE ( _sum, _count )

And you will see:

vkellymsft_0-1631847330607.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my raeply as a solution!

Anonymous
Not applicable

Hi @v-kelly-msft ,

 

Thank you for this solution. It got the correct output that I wanted.

 

However, what if I have a TYPE slicer into the dashboard? The result is still the same which must be only the selected filters only will be computed in the measure.

 

Thank you for your assistance on this.

Change All Function with AllSELECTED hope it will works


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



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.