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
ajazz
Frequent Visitor

Dynamic Reference Line on line chart

Hi there,

I was wondering if it is possible to add a dynamic reference line to a line chart.

In my line chart I have some filtered products by a slicer. On the y-axis i have price and x-axis i have date.

My objective is to show a dynamic reference line, where it takes the cheapest filtered product and adds the value 50 to the price. It should be dynamic, so that it takes the cheapest product from that particular date and not the general cheapest product.

I would like to show the dynamic reference line on the line chart.

I have tried to draw how it should be (the red line is the dynamic reference line that im seeking):

ajazz_0-1628674393059.png

 


Any help would be very appreciated.

Thanks in advance!

1 ACCEPTED SOLUTION

Hi  @ajazz ,

 

Sorry for the late reply.

Create 2 measures as below:

Average =
AVERAGEX (
    FILTER (
        ALLSELECTED ( MedicinPriserUnpivot ),
        'MedicinPriserUnpivot'[Varenummer] = MAX ( MedicinPriserUnpivot[Varenummer] )
            && 'MedicinPriserUnpivot'[Dato] = MAX ( 'MedicinPriserUnpivot'[Dato] )
    ),
    'MedicinPriserUnpivot'[Pris]
)
Measure2 =
VAR _tab =
    CALCULATETABLE (
        VALUES ( 'Vareoversigt'[Varenummer] ),
        FILTER (
            ALL ( Vareoversigt ),
            'Vareoversigt'[Substitutionsgruppe]
                IN FILTERS ( Vareoversigt[Substitutionsgruppe] )
        )
    )
RETURN
    CALCULATE (
        MINX ( ALLSELECTED ( MedicinPriserUnpivot ), [Average] ),
        FILTER (
            ALLSELECTED ( 'MedicinPriserUnpivot' ),
            'MedicinPriserUnpivot'[Dato] = MAX ( 'MedicinPriserUnpivot'[Dato] )
                && 'MedicinPriserUnpivot'[Varenummer] IN _tab
        )
    ) + 50

And you will see:

vkellymsft_0-1629797939477.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

16 REPLIES 16
v-kelly-msft
Community Support
Community Support

Hi @ajazz ,

 

I see your data,how to caculate the reference line?

I took part of your data as below:

vkellymsft_0-1628842239822.png

Could you pls advise me how to get the reference line?What is the calculation logic?

 

 

Best Regards,
Kelly

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

 

Hi again,

It needs to be average price per ProductNumber.
Then a slicer to select 3-4 productnumbers.

Of the "filtered" view, the reference line needs to take the ProductNumber with the lowest price and add +50 to it.

 

Does that make sense?

Hi @ajazz ,

 

Do you mean that the reference line is combined by loweast price of each month +50?

 

Best Regards,
Kelly

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

It needs to be for each date point, so not month. Like lowest price productnumber from monday 15 july 2019 + 50.

ajazz_0-1628846006698.png

 

Hi  @ajazz ,

 

Measure is easy to create,but line chart doesnt support measure as secondary values,what I can think is to put measure as a tooltip,such as below:

vkellymsft_0-1628849320634.png

Or change the visual to "line and stacked column chart instead".

 

Best Regards,
Kelly

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

Hi Kelly,

I just saw that you have attached a copy. Thanks!

I have a question:

I can see it filters values by date. Is it possible to filter the measure by the "Sliced" values in a slicer?

ajazz_0-1629200554500.png

 




Hi @ajazz ,

 

Change "ALL" to "ALLSELECTED " should work,check below:

Measure = CALCULATE(MIN('Table'[Price]),FILTER(ALLSELECTED('Table'),'Table'[Date]=MAX('Table'[Date])))+50

 

Best Regards,
Kelly

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

Hi @v-kelly-msft,

I appreciate you efforts a lot!

We are getting very close, but it seems like its not calculating correct?

 

ajazz_0-1629276105704.png

 

Thanks again!

Hi @ajazz ,

 

I cant reproduce your senario,would you pls share your .pbix file for test?

Remember to remove the confidential information.

 

Best Regards,
Kelly

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

Hi @v-kelly-msft 

I have attached a link to the pbix here with the used datasets.
https://we.tl/t-SuEKSu1Y25


I would recommend you to slice with value 58 in 'Substitutionsgruppe'

ajazz_0-1629356428410.png

 

Huge thanks!!

Hi  @ajazz ,

 

Sorry for the late reply.

Create 2 measures as below:

Average =
AVERAGEX (
    FILTER (
        ALLSELECTED ( MedicinPriserUnpivot ),
        'MedicinPriserUnpivot'[Varenummer] = MAX ( MedicinPriserUnpivot[Varenummer] )
            && 'MedicinPriserUnpivot'[Dato] = MAX ( 'MedicinPriserUnpivot'[Dato] )
    ),
    'MedicinPriserUnpivot'[Pris]
)
Measure2 =
VAR _tab =
    CALCULATETABLE (
        VALUES ( 'Vareoversigt'[Varenummer] ),
        FILTER (
            ALL ( Vareoversigt ),
            'Vareoversigt'[Substitutionsgruppe]
                IN FILTERS ( Vareoversigt[Substitutionsgruppe] )
        )
    )
RETURN
    CALCULATE (
        MINX ( ALLSELECTED ( MedicinPriserUnpivot ), [Average] ),
        FILTER (
            ALLSELECTED ( 'MedicinPriserUnpivot' ),
            'MedicinPriserUnpivot'[Dato] = MAX ( 'MedicinPriserUnpivot'[Dato] )
                && 'MedicinPriserUnpivot'[Varenummer] IN _tab
        )
    ) + 50

And you will see:

vkellymsft_0-1629797939477.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Awesome @v-kelly-msft 

You helped me a bunch! Thanks a lot!

Hi  @ajazz ,

 

Glad to help!🙂

 

Best Regards,
Kelly

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

 

 

Great job!

Is it possible to have multiple lines in a "line and stacked column chart"? If so that could be a good solution.

How does your function for measure look like?

v-kelly-msft
Community Support
Community Support

Hi @ajazz ,

 

Could you pls provide some sample data with expected output for test?

Remember to remove the confidential information.

 

Best Regards,
Kelly

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

Hi,

I have attached a sample data set here:
https://we.tl/t-RNSBlkM5Vf

THANKS!

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.