Forum Discussion
Dynamic Ordering of Calculation Group Items (different order based on visual)
- 1 year ago
Hi Mikee_13
To allow for different orderings of calculation items, you can add additional copies of the calculation item column as well as additional Ordinal columns to the calculation group, along with a few setup steps described below.
This is an extension of the method covered in this blog post.
Hopefully this is the sort of thing you are looking for 🙂
I have attached a simple example PBIX with a model set up in this way with a
Time Intelligencecalculation group.The steps I used to set this up:
- Created the original calculation group called
Time Intelligencewith calculation item columnTime Calc. - Added a calculated column
Time Calc Alternatewhich is just a copy of the original calculation item column:
Time Calc Alternate ='Time Intelligence'[Time Calc] - Added a calculated column
Ordinal Alternatecontaining the alternate ordering of calculation items. I used aSWITCHexpression to set the value based onTime Calcvalue. - Set
Time Calc Alternateto sort byOrdinal Alternate. - Critical step: Set
Time Calc Alternate's Group By Columns property toTime Calc.
See this article for detail on setting this property using Tabular Editor.
After following these steps, you can place either
Time CalcorTime Calc Alternatein a visual and they will function correctly as calculation items and sort as specified by theOrdinalorOrdinal Alternatecolumns.Field parameter to select between calculation group columns
- You can also create a Field Parameter to allow selection between the two orderings by the report consumer, by selecting between
Time CalcorTime Calc Alternate. - In the sample PBIX, I added a slicer to the page for this Field Parameter, but this could be applied via visual-level filter or could be tied to some dynamic logic (see this blog post).
I wouldn't call this a simple solution by any stretch, especially as the Group By Columns property is not accessible in the Power BI Desktop interface! But at least it works and is relatively straightforward to maintain.
Hopefully this is useful, and please post back with any further questions 🙂
- Created the original calculation group called
- 1 year ago
Hi again Mikee_13 ,
Glad the solution for controlling the calculation item sort order worked! 🙂
On the question of filtering calculation items based on the "View" selection, your current measure-based filter might be suffering from too many computations on-the-fly.
Here is one method I tried that seems to perform acceptably with some test data:
PBIX: Calculation item order v2.pbix
1. Create a table
View Time Calcthat contains the required combinations of View and Calculation Item which is then related many-to-one to the field parameter table (Viewin my example).To help create this, I first ensured that the
Ordinalcolumns in the'Time Intelligence'calculation group are blank for items that should be hidden:'Time Intelligence'table:View Time Calc table:
View Time Calc = GENERATE ( SELECTCOLUMNS ( 'View', "View", 'View'[View] ), VAR CurrentView = [View] RETURN CALCULATETABLE ( VALUES ( 'Time Intelligence'[Time Calc] ), SWITCH ( CurrentView, "Summary", NOT ISBLANK ( 'Time Intelligence'[Ordinal Summary] ), "Act vs Bud", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsBud] ), "Act vs Frcst", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsFrcst] ), "Act vs PY", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsPY] ) ) ) )Relationships
2. Create a second calculation group called
Filter Time Intelligencethat blanks out measures when the calc item is not in the set of calc items for that View. It has a single calculation item"Filter Time Calc by View":IF ( SELECTEDVALUE ( 'Time Intelligence'[Time Calc] ) IN VALUES ( 'View Time Calc'[Time Calc] ), SELECTEDMEASURE ( ) )3. Lastly apply
'Filter Time Intelligence'[Filter] = "Filter Time Calc by View"as a filter on the required visuals:Alternatives:
- You could try a blend of your original method using a measure-baesd filter and this method with a table of allowed calculation items.
- Another method I didn't mention (since I don't really encourage it) is simply to create additional copies of each calculation item with a grouping column (
Viewin this case) added to the calculation group. This can be a maintenance nightmare since multiple copies of each calculation item need to be maintained.
I'd be interested in whether the above method improves performance with your model. 🙂
I've got Tabular Editor installed and the solution you provided has worked perfectly. Also the links you supplied were interesting reading too so thank you very much 🙂
I would like to check one more thing if you wouldnt mind.
I have created a measure that applies filtering on the visual so that the selected value from the parameter used for sorting the calculation items also filters the calculation items automatically to only the items related to that view. This is working although it is quite slow so I may be using a poor solution to perform this dynamic filtering. If you get a chance I would be grateful if you could look through my below solution for this to see if it could be improved?
- Field Parameter 'Scope Views' has been created with the following columns from the calculation group: 'Summary', 'Act vs Bud', 'Act vs Frcst', 'Act vs PY'
- I have then created the below measure that returns a boolean value and is applied to the filter in the visual to only show where it returns value 1:
ScopeFilter_CG_Items =
Var SummaryView = {"PY", "BUD", "FRCST", "ACT", "ACT vs FRCST", "ACT vs FRCST %", "ACT vs BUD", "ACT vs BUD %", "ACT vs PY", "ACT vs PY %"}
Var ActVsBudView = {"ACT", "BUD", "ACT vs BUD %"}
Var ActVsFrcstView = {"ACT", "FRCST", "ACT vs FRCST %"}
Var ActVsPYView = {"ACT", "PY", "ACT vs PY %"}
Var SelectedView_Param = MAX('Scope Views'[Scope Views]) // Field Parameter for Calculation Group Columns
Var CurrentCalcItem = SELECTEDVALUE('_CG_Scope Figures'[Summary])
Var result =
SWITCH(SelectedView_Param,
"Summary", INT(CurrentCalcItem IN SummaryView),
"Act vs Bud", INT(CurrentCalcItem IN ActVsBudView),
"Act vs Frcst", INT(CurrentCalcItem IN ActVsFrcstView),
"Act vs PY", INT(CurrentCalcItem IN ActVsPYView),
INT(CurrentCalcItem IN SummaryView)
)
Return
result
This all works nicely and filters my visual with the desired calculation items and they are sorted correctly as per the solution you provided above. It is quite slow and my feeling is that the speed reduced when I introduced the above filtering measure:
Regards
Mike
Hi again Mikee_13 ,
Glad the solution for controlling the calculation item sort order worked! 🙂
On the question of filtering calculation items based on the "View" selection, your current measure-based filter might be suffering from too many computations on-the-fly.
Here is one method I tried that seems to perform acceptably with some test data:
PBIX: Calculation item order v2.pbix
1. Create a table View Time Calc that contains the required combinations of View and Calculation Item which is then related many-to-one to the field parameter table (View in my example).
To help create this, I first ensured that the Ordinal columns in the 'Time Intelligence' calculation group are blank for items that should be hidden:
'Time Intelligence' table:
View Time Calc table:
View Time Calc =
GENERATE (
SELECTCOLUMNS ( 'View', "View", 'View'[View] ),
VAR CurrentView = [View]
RETURN
CALCULATETABLE (
VALUES ( 'Time Intelligence'[Time Calc] ),
SWITCH (
CurrentView,
"Summary", NOT ISBLANK ( 'Time Intelligence'[Ordinal Summary] ),
"Act vs Bud", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsBud] ),
"Act vs Frcst", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsFrcst] ),
"Act vs PY", NOT ISBLANK ( 'Time Intelligence'[Ordinal ActVsPY] )
)
)
)
Relationships
2. Create a second calculation group called Filter Time Intelligence that blanks out measures when the calc item is not in the set of calc items for that View. It has a single calculation item "Filter Time Calc by View":
IF (
SELECTEDVALUE ( 'Time Intelligence'[Time Calc] ) IN VALUES ( 'View Time Calc'[Time Calc] ),
SELECTEDMEASURE ( )
)
3. Lastly apply 'Filter Time Intelligence'[Filter] = "Filter Time Calc by View" as a filter on the required visuals:
Alternatives:
- You could try a blend of your original method using a measure-baesd filter and this method with a table of allowed calculation items.
- Another method I didn't mention (since I don't really encourage it) is simply to create additional copies of each calculation item with a grouping column (
Viewin this case) added to the calculation group. This can be a maintenance nightmare since multiple copies of each calculation item need to be maintained.
I'd be interested in whether the above method improves performance with your model. 🙂
- Mikee_131 year agoRegular Visitor
Hi Owen,
Amazing, you are some kind of DAX wizard 🙂
The above solution has worked for me and performance has improved considerably. I did make a change to this solution where I am using a table created in Excel to list the calculation items that should be displayed for each 'View' as I will find this easier to maintain (although the DAX created table is something I would like to study more as very interested in how that all works).
I was originally thinking along these lines with my solution but couldn't quite figure out how to get it all working with a table.
Thank you again for all your help with this.
Regards
Mike