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

Totals In different Hierarch levels

Hi

Please see below image:

kcanterbury_0-1656486439218.png

My dimension hierarch from biggest to smallest are group label, category label and generic label. The total on category level is correct but it is not correct for the group total. For the group total I would like the average of the totals for each category level but instead im getting the average of all the generic labels. How can I fix this so that power bi takes the average of the category label totals to do the group label total. I tried multiple measures and im getting to the same result, see different measures I used below:

testrating =
CALCULATE('Measure Table'[Actual]/'Measure Table'[Total score],GROUPBY(Visits,Visits[Generic Label],DSM_Store_Visits[Category Label],DSM_Store_Visits[Group Label],
"max rating",AVERAGEX(CURRENTGROUP(),Visits[Field Rating])))
 
test =
VAR gen = ISINSCOPE(Visits[Generic Label])
var cat = ISINSCOPE(Visits[Category Label])
var grp = ISINSCOPE(Visits[Group Label])
var tr = 'Measure Table'[Actual]/'Measure Table'[Total score]
return
switch(
true(),
gen,tr,
cat,tr,
grp,tr,
tr)
 
Base measures used in the final measures:

Actual:

CALCULATE(SUM('Visits'[Field Rating]),'Visits'[Field Rating]=1)

 

Total Score:

CALCULATE(COUNT('Visits'[Field Rating]),'Visits'[Field Rating]<>2 &&'Visits'[Field Rating]<>-1)
 


The answer I should get is (100+100+77,78)/3=92,59


Your help would really be appreciated.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can try this code to do that.

Measure =
SWITCH (
    TRUE (),
    HASONEVALUE ( 'Table'[catagory] ), AVERAGE ( 'Table'[value] ),
    HASONEVALUE ( 'Table'[Group] ),
        AVERAGEX (
            SUMMARIZE (
                'Table',
                [catagory],
                "AVG", CALCULATE ( AVERAGE ( 'Table'[value] ) )
            ),
            [AVG]
        ),
    AVERAGEX (
        SUMMARIZE (
            'Table',
            [Group],
            "A",
                AVERAGEX (
                    SUMMARIZE ( 'Table', [catagory], "AVG", AVERAGE ( 'Table'[value] ) ),
                    [AVG]
                )
        ),
        [A]
    )
)

 

Result:

vchenwuzmsft_0-1656930155066.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

6 REPLIES 6
Anonymous
Not applicable

at the moment the grand total is the average of all the generic label values which I dont want as it is the lowest level

Hi @Anonymous ,

 

You can try this code to do that.

Measure =
SWITCH (
    TRUE (),
    HASONEVALUE ( 'Table'[catagory] ), AVERAGE ( 'Table'[value] ),
    HASONEVALUE ( 'Table'[Group] ),
        AVERAGEX (
            SUMMARIZE (
                'Table',
                [catagory],
                "AVG", CALCULATE ( AVERAGE ( 'Table'[value] ) )
            ),
            [AVG]
        ),
    AVERAGEX (
        SUMMARIZE (
            'Table',
            [Group],
            "A",
                AVERAGEX (
                    SUMMARIZE ( 'Table', [catagory], "AVG", AVERAGE ( 'Table'[value] ) ),
                    [AVG]
                )
        ),
        [A]
    )
)

 

Result:

vchenwuzmsft_0-1656930155066.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.

Anonymous
Not applicable

Group LabelCategory LabelGeneric LabelNew measure

Customer ExperienceB.1B.1.1100.00%
Customer ExperienceB.1B.1.2100.00%
Customer ExperienceB.1B.1.3100.00%
Customer ExperienceB.1B.1.4100.00%
Customer ExperienceB.1B.1.5100.00%
Customer ExperienceB.1B.1.6100.00%
Customer ExperienceB.1B.1.7100.00%
Customer ExperienceB.1B.1.8100.00%
Customer ExperienceB.1B.1.9100.00%
Customer ExperienceB.1B.1.10100.00%
Customer ExperienceB.1B.1.11100.00%
Customer ExperienceB.1B.1.12100.00%
Customer ExperienceB.1B.1.13100.00%
 B.1 Total 100%
Customer ExperienceB.1B.1.14100.00%
Customer ExperienceB.2B.2.1100.00%
Customer ExperienceB.2B.2.2100.00%
Customer ExperienceB.2B.2.3100.00%
Customer ExperienceB.2B.2.4100.00%
Customer ExperienceB.2B.2.5100.00%
Customer ExperienceB.2B.2.6100.00%
Customer ExperienceB.2B.2.7100.00%
Customer ExperienceB.2B.2.8100.00%
 B.2 Total 100%
Customer ExperienceB.3B.3.1100.00%
Customer ExperienceB.3B.3.2100.00%
Customer ExperienceB.3B.3.3100.00%
 B.3 Total 100%
Customer ExperienceB.4B.4.1100.00%
Customer ExperienceB.4B.4.2100.00%
Customer ExperienceB.4B.4.3100.00%
Customer ExperienceB.4B.4.4100.00%
Customer ExperienceB.4B.4.5100.00%
 B.4 Total 100%
Customer ExperienceB.5.1B.5.1.1100.00%
Customer ExperienceB.5.1B.5.1.2100.00%
Customer ExperienceB.5.1B.5.1.3100.00%
Customer ExperienceB.5.1B.5.1.4100.00%
Customer ExperienceB.5.1B.5.1.5100.00%
Customer ExperienceB.5.1B.5.1.6100.00%
Customer ExperienceB.5.1B.5.1.7100.00%
Customer ExperienceB.5.1B.5.1.8100.00%
Customer ExperienceB.5.1B.5.1.9100.00%
 B5.1 Total 100%
Customer ExperienceB.5.2B.5.2.1100.00%
Customer ExperienceB.5.2B.5.2.2100.00%
 B5.2 Total 100%
Customer ExperienceB.5.3B.5.3.1100.00%
Customer ExperienceB.5.3B.5.3.2100.00%
 B5.3 Total 100%
Customer ExperienceB.5.4B.5.4.1100.00%
Customer ExperienceB.5.4B.5.4.2100.00%
Customer ExperienceB.5.4B.5.4.3100.00%
Customer ExperienceB.5.4B.5.4.4100.00%
Customer ExperienceB.5.4B.5.4.5100.00%
Customer ExperienceB.5.4B.5.4.6100.00%
 B5.4 Total 100%
Customer ExperienceB.5.5B.5.5.1100.00%
Customer ExperienceB.5.5B.5.5.2100.00%
 B5.5 Total 100%
Customer ExperienceB.5.6B.5.6.1100.00%
Customer ExperienceB.5.6B.5.6.2100.00%
Customer ExperienceB.5.6B.5.6.3100.00%
Customer ExperienceB.5.6B.5.6.4100.00%
 B5.6 Total 100%
Customer ExperienceB.6B.6.1100.00%
Customer ExperienceB.6B.6.2100.00%
Customer ExperienceB.6B.6.3100.00%
Customer ExperienceB.6B.6.4100.00%
Customer ExperienceB.6B.6.5100.00%
Customer ExperienceB.6B.6.6100.00%
Customer ExperienceB.6B.6.7100.00%
 B6 Total 100%
Customer ExperienceB.7B.7.1100.00%
Customer ExperienceB.7B.7.2100.00%
Customer ExperienceB.7B.7.3 1100.00%
 B7 Total 100%
Customer Experience Total  100%
ProcessesC.1C.1.1100.00%
ProcessesC.1C.1.2100.00%
ProcessesC.1C.1.3100.00%
ProcessesC.1C.1.4100.00%
ProcessesC.1C.1.5100.00%
ProcessesC.1C.1.6100.00%
ProcessesC.1C.1.7100.00%
ProcessesC.1C.1.8100.00%
ProcessesC.1C.1.9100.00%
 C1 Total 100%
ProcessesC.2C.2.1100.00%
ProcessesC.2C.2.2100.00%
ProcessesC.2C.2.30
ProcessesC.2C.2.40
ProcessesC.2C.2.5N/A
ProcessesC.2C.2.6100.00%
ProcessesC.2C.2.7100.00%
ProcessesC.2C.2.8100.00%
ProcessesC.2C.2.9100.00%
ProcessesC.2C.2.10100.00%
 C2 Total 77,78
ProcessesC.3C.3.1100.00%
ProcessesC.3C.3.2100.00%
ProcessesC.3C.3.3100.00%
 C3 Total 100%
Processes Total  92,59
Grand Total  96,29
    
Category TotalBased on the average on the generic label value  
Group totalBased on the average of the Category Label vale  
Grand totalBased on the average of the group label value  

 

Hi please assist. Those are the totals i am expecting. I am achieving the correct category and group totals but my grand total is incorrect.

Anonymous
Not applicable

Hi

this is still summarising the totals on the generic labels instead of the next hierarchy. The DAX in my previous comment works but it is still summarising the grand total on the average of the generic labels and i want it to summarize it on the average of the group labels

Anonymous
Not applicable

Hi
I got the result using the below measure but it is 100% correct:
New measure2 =
VAR Category =
ADDCOLUMNS(Summarize(Visits, DSM_Store_Visits[Generic Label],Visits[Category Label],Visits[Group Label]), "Total Rating",
CALCULATE(sum(Visits[Actual])/sum(Visits[Total Score]) ) )
return
averagex(Summarize(Category, [Category Label],Visits[Group Label]),[Total Rating])

Using this the group label and category label total is correct  but the overall total is incorrect. The overall total must take the average of the the group label. One of the group labels is processes and the other which is not shown above is customers. At the moment the total is taking all the aveage of all the category level totals and I want it to be a level higher. How would i do this?
amitchandak
Super User
Super User

@Anonymous , Try like

 


if(isfiltered(Visits[Group Label]) || ISINSCOPE(Visits[Group Label]) || ISINSCOPE(Visits[Category Label]) ,
switch(
true(),
gen,tr,
cat,tr,
grp,tr,
tr)
, averageX(Values(Visits[Category Label]), tr))

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.