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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Akad
Frequent Visitor

Constant line based on the level of hierarchy

Hi everyone,

 

I have a scatter chart with a hierarchy as values (let's say Country/Region/City).

I want to add a constant line on this chart based on the level of hierarchy the user is seeing. For example is the user is on the Country level the constant line would be the result of calculation A, on the Region level it would be the result of calculation B and on the City level it would be the result of calculation C.

I have created a measure that do the job using the ISINSCOPE() function and looks like this:

 

ConstantLine =
VAR ResultCountry =
MEDIANX(
    CALCULATETABLE(
        VALUES( 'Location'[Country] ),
        ALL(
            'Location'[Country],
            'Location'[Region],
            'Location'[City]
        )
    ),
    CALCULATE(
        DISTINCTCOUNT( Sales[ID] ),
        Sales[HasDiscount] = TRUE()
    )
)
VAR ResultRegion =
MEDIANX(
    CALCULATETABLE(
        VALUES( 'Location'[Region] ),
        ALL(
            'Location'[Country],
            'Location'[Region],
            'Location'[City]
        )
    ),
    CALCULATE(
        DISTINCTCOUNT( Sales[ID] ),
        Sales[HasDiscount] = TRUE()
    )
)
VAR ResultCity =
MEDIANX(
    CALCULATETABLE(
        VALUES( 'Location'[City] ),
        ALL(
            'Location'[Country],
            'Location'[Region],
            'Location'[City]
        )
    ),
    CALCULATE(
        DISTINCTCOUNT( Sales[ID] ),
        Sales[HasDiscount] = TRUE()
    )
)

VAR Result =
SWITCH(
    TRUE(),
    ISINSCOPE( 'Location'[Country] ),
    ResultCountry,
    ISINSCOPE( 'Location'[Region] ),
    ResultRegion,
    ISINSCOPE( 'Location'[City] ),
    ResultCity
)

RETURN
Result

 

 

My problem is that it simply doesn't work 😞

I mean the easure seems to work because when I use it as Tooltip on my scatter plot I see the correct value when I hover a point.

But when I use the measure as a dynamic constant line it returns an empty result. I tried to replace ISINSCOPE with ISFILTERED but the result is the same. So the measure is working but I can't find a way to make the ISINSCOPE work in the context of a constant line. Can someone help me with this? Is there any workaround?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Akad , I think you can use field parameter in values of scatter, should be able switch measure like I have done in TOPN

 

Power BI Field Parameters — A Quick way for Dynamic Visuals: https://amitchandak.medium.com/power-bi-field-parameters-a-quick-way-for-dynamic-visuals-fc4095ae9af...
Power BI Field Parameters- Measure Slicer and Axis/Dimension slicer: https://youtu.be/lqF3Wa1FllE
Switch TOPN with Field Parameters: https://amitchandak.medium.com/switch-topn-with-field-parameters-299a0ae3725f

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Akad , I think you can use field parameter in values of scatter, should be able switch measure like I have done in TOPN

 

Power BI Field Parameters — A Quick way for Dynamic Visuals: https://amitchandak.medium.com/power-bi-field-parameters-a-quick-way-for-dynamic-visuals-fc4095ae9af...
Power BI Field Parameters- Measure Slicer and Axis/Dimension slicer: https://youtu.be/lqF3Wa1FllE
Switch TOPN with Field Parameters: https://amitchandak.medium.com/switch-topn-with-field-parameters-299a0ae3725f

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you @amitchandak your solution works fine!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.