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. 🙂
Hi Owen,
Thank you for the detailed reply and it looks like exactly what I am after. I need to await approval to get Tabular Editor to try this out but will let you know the results 🙂