Forum Discussion

EOW's avatar
EOW
Icon for Advocate II rankAdvocate II
1 year ago

How to use a calculation group as a column switcher for multiple column groups?

I've got a report tracking yields at different steps in production, formatted in the following manner:

 

LotProductFinish FlagStp1 YieldStp1 Target StaticStp1 Target LiveStp1 Target FileStp2 YieldStp2 Target StaticStp2 Target LiveStp2 Target File
A101W1Y98%96%95%95%95%92%90%92%
A102W1Y97%96%95%95%91%92%90%92%
A103W2Y90%89%87%88%82%84%82%83%
A104W2N87%89%87%88%80%84%82%83%

 

I want to slice between Static, Live and File Targets in my measures, Is there a way to leverage a calulcation group and simplify the measures I've written. I've put the target set I want to use in a table called 'Target Use'.

 

 

 

Stp1 Target = 
var FilterRows = FILTER('Data', 'Data'[Finish Flag] = "Y")
var TargUse = SELECTEDVALUE('Target Use'[TargetToUse])

return
SWITCH(TRUE()
, TargUse = "Static Targets"	, AVERAGEX(FilterRows, Data[Stp1 Target Static])
, TargUse = "Live Targets"		, AVERAGEX(FilterRows, Data[Stp1 Target Live])
, TargUse = "File Targets"		, AVERAGEX(FilterRows, Data[Stp1 Target File])
, AVERAGEX(FilterRows, Data[Stp1 Target Static])
)



Stp2 Target = 
var FilterRows = FILTER('Data', 'Data'[Finish Flag] = "Y")
var TargUse = SELECTEDVALUE('Target Use'[TargetToUse])

return
SWITCH(TRUE()
, TargUse = "Static Targets"	, AVERAGEX(FilterRows, Data[Stp2 Target Static])
, TargUse = "Live Targets"		, AVERAGEX(FilterRows, Data[Stp2 Target Live])
, TargUse = "File Targets"		, AVERAGEX(FilterRows, Data[Stp2 Target File])
, AVERAGEX(FilterRows, Data[Stp2 Target Static])
)

 

 

 

Is there a way to use calculation groups to generalise the measures?

1 Reply

  • LYPowerBI's avatar
    LYPowerBI
    Frequent Visitor

    unpivot the target columns may help you.