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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Hierarchy Drill Down Logic

Hello,

 

I have a dataset that I would like to summarize in a matrix with a drill down option. I have attached a general straw man of what my data will look like. For this example, there are 4 levels in the hierarchy and level 4 is the most granular level while 1 is the most general. The problem that I am having is that for the drill down, all of the totals going up by level are not raw sums, and as a result I have a "total" entry for each level (Ex: a total for level 3a that is composed of 4a and 4b). Furthermore, I was wondering if there was a way for me to tell the data to take the total for the outer levels instead of aggregating by summing?

 

Note, all totals are greater than the individual components so I did try to make the data column aggregate by max, however, I ran into the issue of each of the total rows showing up in the drill down with the individual component (Ex: for the 3a drill down I had a line for 4a, 4b, and total). Therefore, I would like to figure out a measure that has the logic described above.

 

Please let me know if this is not clear or if more information/context is needed.

Thanks,

Nick

Level 1Level 2Level 3Level 4Data
Category 1TotalTotalTotalx
Category 1Category 2aTotalTotalx
Category 1Category 2bTotalTotalx
Category 1Category 2aCategory3aTotalx
Category 1Category 2aCategory3bTotalx
Category 1Category 2bCategory3cTotalx
Category 1Category 2bCategory3dTotalx
Category 1Category 2aCategory3aCategory 4ax
Category 1Category 2aCategory3aCategory 4bx
Category 1Category 2aCategory3bCategory 4cx
Category 1Category 2aCategory3bCategory 4dx
Category 1Category 2bCategory3cCategory 4ex
Category 1Category 2bCategory3cCategory 4fx
Category 1Category 2bCategory3dCategory 4gx
Category 1Category 2bCategory3dCategory 4hx
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

You can try this measure:

Measure = IF(

    ISINSCOPE('Table'[level4]),

    SUM('Table'[Data]),

    IF(ISINSCOPE('Table'[level3]),

    CALCULATE(

        VALUES('Table'[Data]),

        FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level3]))),

        IF(ISINSCOPE('Table'[level2]),

        CALCULATE(

            VALUES('Table'[Data]),

            FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level2]))),

            CALCULATE(

                VALUES('Table'[Data]),

                FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level1]))))))

 

And you can get what you want, like this:

v-robertq-msft_0-1602578778157.png

 

You can refer to the pbix file here:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/xiaoxin_qiuyunus_onmicrosoft_com/EbBdKfC-VYRJkSCBrmZsjWABXKdWMwQ5v7AHosGvqjfrPw?e=vJweci 

 

If this solution can not meet your requirement, please show me your expected output and detailed logic.

 

Best Regards,

Community Support Team _Robert Qin

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

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

You can try this measure:

Measure = IF(

    ISINSCOPE('Table'[level4]),

    SUM('Table'[Data]),

    IF(ISINSCOPE('Table'[level3]),

    CALCULATE(

        VALUES('Table'[Data]),

        FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level3]))),

        IF(ISINSCOPE('Table'[level2]),

        CALCULATE(

            VALUES('Table'[Data]),

            FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level2]))),

            CALCULATE(

                VALUES('Table'[Data]),

                FILTER(ALL('Table'),'Table'[Category] = MAX('Table'[level1]))))))

 

And you can get what you want, like this:

v-robertq-msft_0-1602578778157.png

 

You can refer to the pbix file here:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/xiaoxin_qiuyunus_onmicrosoft_com/EbBdKfC-VYRJkSCBrmZsjWABXKdWMwQ5v7AHosGvqjfrPw?e=vJweci 

 

If this solution can not meet your requirement, please show me your expected output and detailed logic.

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

This helped thank you. However, I am now having a problem in my measure with looking up the quarter. I have copied below the formula below. My issue is that although I have stated I would like to look at the previous quarter, my formula is still looking up the current quarter. If there are any context pieces that I am missing please let me know.

 

Thanks,

Nick

 

Prior Quarter =
VAR PriorQuarter = PREVIOUSQUARTER('Output for BI Testing'[Date])

RETURN
IF(
ISINSCOPE('Output for BI Testing'[Level 5]),
CALCULATE(SUMX('Output for BI Testing', [Report_Amount]),
FILTER('Output for BI Testing', AND([Category] = 5, AND([Level 5] <> "Total", PriorQuarter ) ) ) ),
IF(ISINSCOPE('Output for BI Testing'[Level 4]),
CALCULATE(SUMX('Output for BI Testing', [Report_Amount]),
FILTER('Output for BI Testing', AND([Category] = 4, AND([Level 4] <> "Total", PriorQuarter ) ) ) ),
IF(ISINSCOPE('Output for BI Testing'[Level 3]),
CALCULATE(SUMX('Output for BI Testing', [Report_Amount]),
FILTER('Output for BI Testing', AND([Category] = 3, AND([Level 3] <> "Total", PriorQuarter ) ) ) ),
IF(ISINSCOPE('Output for BI Testing'[Level 2]),
CALCULATE(SUMX('Output for BI Testing', [Report_Amount]),
FILTER('Output for BI Testing', AND([Category] = 2, AND([Level 2] <> "Total", PriorQuarter ) ) ) ),
CALCULATE(SUMX('Output for BI Testing', [Report_Amount]),
FILTER('Output for BI Testing', AND([Category] = 1, PriorQuarter ) ) )
))))
Anonymous
Not applicable

Also, I have done some spot checks on quarters that do not have data for previous quarters and the formula knows that and shows 0 for those quarters. The issue arises when the data is there for prior quarters.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.