Forum Discussion
Display Multiple YoY% Changes in a Line Chart Using a Field Parameter
Hi all,
My goal is to show multiple YoY%-Changes lines in a line chart based on a (multiple)selection of a field paramter.
I do have multiple measures that all show the sum of different columns.
E.G.
Sales = SUM(Table['Sales'])
Orders = SUM(Table['Orders'])
...
I could create for each of these measure a new measure with the calculation like - but i want to avoid having to create like 20 of these measures:
Sales_YoY% =
VAR __CV = [Sales]
VAR __PV = CALCULATE([Sales],SAMEPERIODLASTYEAR('Date'[Date]))
VAR __DIFF = __CV-__PV
RETURN
DIVIDE(__DIFF,__PV, BLANK())
When i use calculation groups it does work with a table/matrix visual. However if i try to use it on a bar or line chart it only works if i select a single measure - which makes sense - i guess - as it uses SELECTEDMEASURE().
I tried to put the "parameter" on the Y-Axis and the "calculation item" on the legend.
Code for Calculation Group:
YoY% =
VAR __CV = SELECTEDMEASURE()
VAR __PV = CALCULATE(SELECTEDMEASURE(),SAMEPERIODLASTYEAR('Date'[Date]))
VAR __DIFF = __CV-__PV
RETURN
DIVIDE(__DIFF,__PV, BLANK())
Is there any way to manipulate multiple measures without creating a new measure for each of them?
Thanks.
3 Replies
- rajendraongole1Super User
Hi BoSe2828 - you can utilize calculation groups , to get the multiple Year-over-Year (YoY%) change lines in a single Power BI line chart based on the selection of multiple field parameters, without creating individual YoY measures for each one.
example:
YoY% =
VAR __CV = SELECTEDMEASURE()
VAR __PV = CALCULATE(SELECTEDMEASURE(), SAMEPERIODLASTYEAR('Date'[Date]))
VAR __DIFF = __CV - __PV
RETURN
DIVIDE(__DIFF, __PV, BLANK())This calculation group will dynamically apply the YoY% calculation to any measure in the model that is used in the visual.
This solution may face limitations when visualizing multiple measures simultaneously because SELECTEDMEASURE() applies to a single measure. If you're selecting multiple measures and expect to see multiple lines in the same chart, you might need to adapt the setup to handle dynamic measure switching better.
you can use variables in the calculation group to conditionally calculate multiple measures in one visual and apply the YoY% calculation without separating them into individual measures.
Hope the above information helps in your scenerio
- BoSe2828Frequent Visitor
Hi rajendraongole1 ,
as mentioned I'm already using a calculation group and it works fine with a table or matrix visual. My issues comes with displaying mutliple lines/columns in a line or column chart.- AnonymousNot applicable
Hi, BoSe2828
I've tested and can't use calculation groups to display multiple lines in a line chart. Separate neasure are still needed, and each measure can correspond to a line.
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.