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
badger123
Resolver I
Resolver I

Max of Summed Values of a Category

Hello,

 

I am hoping for some help with the following, after trying and failing numerous times. I have created two dummy tables for simplicity (see below). These tables have a one-to-many relationship based on the ID.

 

I am creating a page in my report that focuses on one Item in one Country at a time. There are various slicers, including Region. I am looking to create some benchmarks to compare the selected Item with its Category benchmarks. The benchmark I am struggling to create is the Max total Volume per Category, let's call this MaxBenchmark.

 

This is how I want it to work. If I select Item 1 and Country UK, total Volume would be 350 and MaxBenchmark should be 2,300 because Item 3 has the highest total Volume in Category A. If I select Item 2 and Country UK, total Volume would be 850, and MaxBenchmark should also be 850 because Item 2 has the highest total vol in Category B. An added complication, if I now select Region UKE, total Volume would be 50 and MaxBenchmark should be 100, because Item 4 has the highest Volume per Category in that Region. 

 

Table1Table1Table2Table2

I have been going round in circles with this for days so any guidance would be much appreciated! 

 

Thanks 🙂

 

 

 

2 ACCEPTED SOLUTIONS

Hi @badger123

 



We'll create the two measures you talk about and the you can use them as you like in the gauge.

1. Set the Table2[ID] and Table1[Country] and Table1[Region] in slicers as you described
2. Create the measure for the selected item volume (which I believe you have already):
 

VolumeMeasure = SUM(Table1[ID])

3. Create the measure for the Max:

MaxBenchmark =
VAR _ItemCategory =
    SELECTEDVALUE ( Table2[Category] )
VAR _CategoryVolumes =
    ADDCOLUMNS (
        CALCULATETABLE (
            VALUES ( Table2[ID] );
            Table2[Category] = _ItemCategory;
            ALL ( Table2 )
        );
        "VolumeCol"; [VolumeMeasure]
    )
VAR _MaxInCat =
    MAXX ( _CategoryVolumes; [VolumeCol] )
RETURN
    _MaxInCat

Code formatted with   www.daxformatter.com

View solution in original post

@badger123

 

I guess you've done stg different from what I described. It's working on my end. Have a look at this file.

View solution in original post

12 REPLIES 12
AlB
Super User
Super User

Hi @badger123

 

How would you want this? In two Card visuals, one with TotalVolume and one with  MaxBenchMark?

Can you please paste the data in table /text instead of on a screen capture? So that it can be easily copied?

 

   

Hi @badger123

 



We'll create the two measures you talk about and the you can use them as you like in the gauge.

1. Set the Table2[ID] and Table1[Country] and Table1[Region] in slicers as you described
2. Create the measure for the selected item volume (which I believe you have already):
 

VolumeMeasure = SUM(Table1[ID])

3. Create the measure for the Max:

MaxBenchmark =
VAR _ItemCategory =
    SELECTEDVALUE ( Table2[Category] )
VAR _CategoryVolumes =
    ADDCOLUMNS (
        CALCULATETABLE (
            VALUES ( Table2[ID] );
            Table2[Category] = _ItemCategory;
            ALL ( Table2 )
        );
        "VolumeCol"; [VolumeMeasure]
    )
VAR _MaxInCat =
    MAXX ( _CategoryVolumes; [VolumeCol] )
RETURN
    _MaxInCat

Code formatted with   www.daxformatter.com

Hi @AlB,

 

Since you were so helpful this, I'm wondering how to create a similar measure, except this time dealing with the weighted average of Growth for the selected Category. I have a measure that calculates the weighted average for one item (see below), but struggling to create a measure that successfully calculates the weighted average for a Category. 

 

Weighted_Average_Growth = DIVIDE (
SUMX ( 'Table 2', 'Table 2'[growth] * 'Table 2'[volume] ),
CALCULATE ( SUM ( 'Table 2'[volume] ), ALLSELECTED('Table 2'[id])))

IDID2CountryRegionVolumeGrowth
11CUKUKC10010%
11DUKUKD20020%
11EUKUKE5030%
22CUKUKC50010%
22DUKUKD30050%
22EUKUKE5060%
33CUKUKC1000100%
33DUKUKD800150%
33EUKUKE500200%
44CUKUKC100-30%
44DUKUKD200-40%
44EUKUKE100-10%

@badger123

 

Try this, with Table2[Category] in the slicer and the measure for instance in Card visual.

Table2 is as previously, Table3 the new one that you show with the growth.

 

WeightedAverageGrowthCat =
DIVIDE (
    SUMX ( Table3; Table3[Growth] * Table3[volume] );
    SUM ( Table3[volume] )
)

Code formatted with   www.daxformatter.com

Hi @AlB

 

I don't want to use a slicer for category, I'm looking to do the same as before where an item is selected and the weighted average should be calculated based on the corresponding category. I'm guessing I will need to take a similar approach combining this... 

 

VAR _ItemCategory =
    SELECTEDVALUE ( Table2[Category] )

 

and this... 

 

WeightedAverageGrowthCat =
DIVIDE (
    SUMX ( Table3; Table3[Growth] * Table3[volume] );
    SUM ( Table3[volume] )
)

but don't quite know what that measure would be?!  

Hi @AlB

 

I don't want to use a slicer for category, I'm looking to do the same as before where an item is selected and the weighted average should be calculated based on the corresponding category. I'm guessing I will need to take a similar approach combining this... 

 

VAR _ItemCategory =
    SELECTEDVALUE ( Table2[Category] )

 

and this... 

WeightedAverageGrowthCat =
DIVIDE (
    SUMX ( Table3; Table3[Growth] * Table3[volume] );
    SUM ( Table3[volume] )
)

but don't quite know what that measure would be?!  

@badger123

Yeah you could follow the same logic, or change it a bit:

Table2 is as previously, Table3 the new one that you show with the growth.

 

WeightedAverageGrowthCat_V2 =
VAR _ItemCategory =
    SELECTEDVALUE ( Table2[Category] )
RETURN
    CALCULATE (
        DIVIDE (
            SUMX (
                Table3;
                Table3[Growth] * Table3[volume]
            );
            SUM ( Table3[volume] )
        );
        CALCULATETABLE (
            VALUES ( Table2[ID] );
            Table2[Category] = _ItemCategory;
            ALL ( Table2 )
        )
    )

 

Code formatted with   www.daxformatter.com

@AlB Awesome! Thank you so much! 🙂 

Thanks for the help @AlB , although it's still not working in the way I want it to. I have tried your suggested measures and MaxBenchmark simply returns the summed volume of the selected item. I think this is due to the first measure maybe? Do you have any thoughts? 

@badger123

 

I guess you've done stg different from what I described. It's working on my end. Have a look at this file.

@AlB you're right! It was the relationships I had created that were causing the issues. You're measures work perfectly and I have now fixed my relationships so it works in my context too. Thanks so much 🙂 

Hi @AlB

 

Thanks for getting back to me. I have included tables below. I'm actually looking to use these measures in the Gauge visual. 

 

IDID2CountryRegionVolume
11CUKUKC100
11DUKUKD200
11EUKUKE50
22CUKUKC500
22DUKUKD300
22EUKUKE50
33CUKUKC1000
33DUKUKD800
33EUKUKE500
44CUKUKC100
44DUKUKD200
44EUKUKE100

 

IDItemCategory
1Item 1Cat A
2Item 2Cat B
3Item 3Cat A
4Item 4Cat B
5Item 5Cat C
6Item 6Cat A

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.

Top Solution Authors