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

Dynamically calculate measures based on a flag within levels of hierarchy

Hi,

I have a clustered bar chart with hierarchical data on Axis and couple of measures in Value. Sample source data looks like below:scenario.JPG

 

Here the hierarchy is Object->Sub-Object->Leaf-Object.

The issue I have is that I want to display the Staging Count and Final Count values where the Main flag for Object='Y' for Parent i.e. Object. 

Similarly, I want to display count values where the Main flag for Sub-Object ='Y' for Sub-object when I drill down to the Sub-object level.

Current behaviour of PBI is its summing using SUM(Staging Count) for object and sub-object levels, by default.

What I have tried: Used analytical functions in Oracle to find the right count that has flag set to 'Y' and use FIRST() to display the count. But the problem with that is when I drill down the count value does not change which is expected from PBI. How do I dynamically change the flag fields at different levels of hierarchy and display its count.expected_output.JPG

Thanks

Rav

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @saravananravim ,

 

We can create two measures using following DAX to meet your need.

 

StagingCountMeasure =
IF (
    ISINSCOPE ( 'Table'[Leaf-Object] ),
    CALCULATE ( SUM ( 'Table'[Staging Count] ) ),
    IF (
        ISINSCOPE ( 'Table'[Sub-Object] ),
        CALCULATE (
            SUM ( 'Table'[Staging Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Sub-Object] = "Y" )
        ),
        CALCULATE (
            SUM ( 'Table'[Staging Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Object] = "Y" )
        )
    )
)
FinalCountMeasure =
IF (
    ISINSCOPE ( 'Table'[Leaf-Object] ),
    CALCULATE ( SUM ( 'Table'[Final Count] ) ),
    IF (
        ISINSCOPE ( 'Table'[Sub-Object] ),
        CALCULATE (
            SUM ( 'Table'[Final Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Sub-Object] = "Y" )
        ),
        CALCULATE (
            SUM ( 'Table'[Final Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Object] = "Y" )
        )
    )
)

Then we can create the chart as you wish.

 

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-1.pngDynamically-calculate-measures-based-on-a-flag-within-levels-of-2.png

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-3.png

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-4.png

 

BTW, pbix as attached.

 

Community Support Team _ DongLi
If this post helps, then please consider Accept it as the solution to help the other members find it more 

Community Support Team _ Dong Li
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

1 REPLY 1
v-lid-msft
Community Support
Community Support

Hi @saravananravim ,

 

We can create two measures using following DAX to meet your need.

 

StagingCountMeasure =
IF (
    ISINSCOPE ( 'Table'[Leaf-Object] ),
    CALCULATE ( SUM ( 'Table'[Staging Count] ) ),
    IF (
        ISINSCOPE ( 'Table'[Sub-Object] ),
        CALCULATE (
            SUM ( 'Table'[Staging Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Sub-Object] = "Y" )
        ),
        CALCULATE (
            SUM ( 'Table'[Staging Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Object] = "Y" )
        )
    )
)
FinalCountMeasure =
IF (
    ISINSCOPE ( 'Table'[Leaf-Object] ),
    CALCULATE ( SUM ( 'Table'[Final Count] ) ),
    IF (
        ISINSCOPE ( 'Table'[Sub-Object] ),
        CALCULATE (
            SUM ( 'Table'[Final Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Sub-Object] = "Y" )
        ),
        CALCULATE (
            SUM ( 'Table'[Final Count] ),
            FILTER ( 'Table', 'Table'[Main flag for Object] = "Y" )
        )
    )
)

Then we can create the chart as you wish.

 

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-1.pngDynamically-calculate-measures-based-on-a-flag-within-levels-of-2.png

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-3.png

Dynamically-calculate-measures-based-on-a-flag-within-levels-of-4.png

 

BTW, pbix as attached.

 

Community Support Team _ DongLi
If this post helps, then please consider Accept it as the solution to help the other members find it more 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.