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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
lafakios
Helper I
Helper I

How to show average of item values with the right filtering

Hi,

 

I would like to create a visual based on the below data which should show the average Param value of the three Item_IDs (with have the highest SortKey) of an Item . The Item shall be selected with a page slicer.

 

I added the two below measures:

 

ReleaseRank =

 

RANKX(ALLSELECTED('item_values'), CALCULATE(SUM('item_values'[SortKey])), ,DESC, Dense)

 

 

Average_Of_The_Three_Latest_ItemIDs_of_An_Item =

 

VAR latest = CALCULATE(MAX('Item_values'[Param]), FILTER(ALLSELECTED('Item_values'), 'Item_values'[ReleaseRank] = 1))
VAR secondlatest = CALCULATE(MAX('Item_values'[Param]), FILTER(ALLSELECTED('Item_values'), 'Item_values'[ReleaseRank] = 2))
VAR thirdlatest = CALCULATE(MAX('Item_values'[Param]), FILTER(ALLSELECTED('Item_values'), 'Item_values'[ReleaseRank] = 3))
return IF(AND(NOT(ISBLANK(secondlatest)), NOT(ISBLANK(thirdlatest))),
              (latest + secondlatest + thirdlatest) / 3,
                  IF(AND(NOT(ISBLANK(secondlatest)), ISBLANK(thirdlatest)),
                     (latest + secondlatest) / 2,
                        latest))  

 

The visual does provide the average value of the selected Item in the slicer, however it also includes all other Items which are present in the 'item_values' Table. I have tried different alternatives in the Calculate-filter for only showing the selected Item's average without any luck.

 

I believe that the above measure formulas and logic could also be written in a better way. 

 

Thanks for your support.

 

Regards,

Akis

 

'item_values' Table

 

Item_IDItemParamSortKey
ItemA 1.4 ItemA01040000
ItemA 1.3 ItemA11030000
ItemA 1.2ItemA21020000
ItemA 1.1ItemA31010000
ItemA 1.0ItemA51000000
ItemB 1.3 ItemB201030000
ItemB 1.2ItemB21020000
ItemB 1.1ItemB31010000
ItemB 1.0ItemB161000000
1 ACCEPTED SOLUTION
ArwaAldoud
Skilled Sharer
Skilled Sharer

Hi @lafakios  try this 

ReleaseRank =
VAR CurrentItem = SELECTEDVALUE('item_values'[Item])

RETURN
    IF(
        NOT(ISBLANK(CurrentItem)), -- Ensures an item is selected
        RANKX(
            FILTER(
                ALLSELECTED('item_values'),
                'item_values'[Item] = CurrentItem
            ),
            CALCULATE(MAX('item_values'[SortKey])), -- Ensures a single value per row
            ,
            DESC,
            DENSE
        )
    )
 
Average_Of_The_Three_Latest_ItemIDs_of_An_Item =
VAR CurrentItem = SELECTEDVALUE('item_values'[Item])

VAR Top3 =
    TOPN(3,
        FILTER(
            ALLSELECTED('item_values'),
            'item_values'[Item] = CurrentItem
        ),
        'item_values'[SortKey], DESC
    )

VAR Top3Avg = AVERAGEX(Top3, 'item_values'[Param])

RETURN
    IF(NOT(ISBLANK(CurrentItem)), Top3Avg)
 
 

If this response was helpful, please accept it as a solution and give kudos to support other community members.

 

View solution in original post

4 REPLIES 4
ArwaAldoud
Skilled Sharer
Skilled Sharer

Hi @lafakios  try this 

ReleaseRank =
VAR CurrentItem = SELECTEDVALUE('item_values'[Item])

RETURN
    IF(
        NOT(ISBLANK(CurrentItem)), -- Ensures an item is selected
        RANKX(
            FILTER(
                ALLSELECTED('item_values'),
                'item_values'[Item] = CurrentItem
            ),
            CALCULATE(MAX('item_values'[SortKey])), -- Ensures a single value per row
            ,
            DESC,
            DENSE
        )
    )
 
Average_Of_The_Three_Latest_ItemIDs_of_An_Item =
VAR CurrentItem = SELECTEDVALUE('item_values'[Item])

VAR Top3 =
    TOPN(3,
        FILTER(
            ALLSELECTED('item_values'),
            'item_values'[Item] = CurrentItem
        ),
        'item_values'[SortKey], DESC
    )

VAR Top3Avg = AVERAGEX(Top3, 'item_values'[Param])

RETURN
    IF(NOT(ISBLANK(CurrentItem)), Top3Avg)
 
 

If this response was helpful, please accept it as a solution and give kudos to support other community members.

 

Thank you very much for the support provided!

The two provided formulas did deliver the wanted results.

 

Regards,

Akis

You're very welcome @lafakios  😊 I'm glad that it helped you.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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