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
hungcht
Regular Visitor

Matrix Visualization - Hiding subcate, but keep the highest level by measure with aggregate(subcate)

Dear Community, I have following these table:

1. table dim_structure_report:

hungcht_1-1694761118102.png

2. table gross_sale_test_data:

hungcht_2-1694761152434.png

3. No relationship.

hungcht_0-1694761030887.png

Then i created a Matrix visualization:

hungcht_5-1694761310019.png

with config:

hungcht_4-1694761289276.png

and measure 0.select_measure_test

 

 

0.select_measure_test = 
VAR SelectedLevel = SELECTEDVALUE(dim_structure_report[metric])
VAR SelectedSubLevel = SELECTEDVALUE(dim_structure_report[sub_1])
VAR NumSubLevels =
    CALCULATE(
        DISTINCTCOUNT(dim_structure_report[sub_1]),
        ALL(dim_structure_report),
        dim_structure_report[metric] = SelectedLevel
    )
VAR MaxSubLevelValue =
    CALCULATE(
        MAXX(dim_structure_report, [sub_1]),
        ALL(dim_structure_report),
        dim_structure_report[metric] = SelectedLevel
    )
RETURN
    SWITCH(
        TRUE(),
        SelectedSubLevel = "mkt_promotion", // Higher level, specific metric
            [promotion],
        SelectedLevel = "gross_sale" && NumSubLevels > 1, // 'gross_sale' metric with multiple sub_1 levels
            BLANK(),
        SelectedSubLevel = "gross_sale", // 'gross_sale' sub_1 level
            IF(NumSubLevels = 1, [gross_sale], MaxSubLevelValue),
        SelectedSubLevel = "mkt",
            [mkt],
        SelectedSubLevel = "promotion",
            [promotion],
        SelectedSubLevel = "ads_spend",
            [mkt] + [promotion],
        SelectedSubLevel = "%ads_spend",
            DIVIDE(([mkt] + [promotion]), [gross_sale]),
        SelectedSubLevel = "profit",
            [gross_sale] - ([mkt] + [promotion]),
        SelectedSubLevel = "%profit",
            DIVIDE(([gross_sale] - ([mkt] + [promotion])), [gross_sale]),
        BLANK() // Default case
    )

 

 

But the result is not my expecting, so i want my results to be like this in each situation:

hungcht_6-1694761708569.png

1. If metric only have 1 sub_1 value, that sub_1 value will not show up when click on (+) (-) expand or collapse, and the metric value will be like its sub_1 value.

2. If metric has many sub_1 value, that sub_1 value will show up when click on (+) (-) expand or collapse, and the metric value will be like its sum of (sub_1 value).

3. If metric has many sub_1 value in clude percentage %, that sub_1 value will show up when click on (+) (-) expand or collapse, and the metric value will be like a specific measure like the line CM Sell In External.

 

I have searched some method, and found this keywork switch(), isinscope(), if(). But dont know how to use.

 

I hope some one experienced in this can rewrite my measure to make it works and this will help me so much.

 

Thank you and have a good day.

 

My attached file:

pbix file for your testing 

 

 

 

1 REPLY 1
MFelix
Super User
Super User

Hi @hungcht ,

 

for this you need a parent child hierarchy:

 

https://www.daxpatterns.com/parent-child-hierarchies/


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.