Forum Discussion
Need help with Measure for Matrix Table and Top 5
- 3 years ago
Have you tried sorting by the sum measure in descending order?
- 3 years ago
I would go for:
Ref =
[Sum of Total Gross Incurred] * 1000000000000 + COUNT(LossRunToExcel[Reporting Location City]) - 3 years ago
I got the first example to work in main file. Thank you for all the help. I will need more time this weekend to try the more creative and visual 2nd option.
- 3 years ago
Yes, it's definitely an issue in the service. You need to sort by the city field to get the axis to respect the structure:
It actually emulates the problem we used to have in Desktop when you turned off concatenate fields: for the setting to take effect, you needed to sort the axis by the fields:
It might be worth reporting the issue on the issues forum:
Ok, I've been playing around with the clustered column chart and this is what I have so far:
Change the [Sort measure] to:
Sort measure =
VAR _FreqByCity =
CALCULATE (
[Count Frequency],
FILTER (
ALL ( InjuryCause[Cause Grouping] ),
[Top 5 by frequency and Incurred] < 6
)
)
VAR _LN =
LEN (
FORMAT (
CALCULATE (
[Count Frequency],
ALL ( 'LossRunToExcel'[Reporting Location City] )
),
"text"
)
)
VAR _Pre =
_FreqByCity
* POWER ( 10, _LN * 2 )
VAR _Inc =
CALCULATE (
RANKX (
ALLSELECTED ( LossRunToExcel[Reporting Location City] ),
[Sum of Total Gross Incurred],
,
ASC,
DENSE
),
ALLSELECTED ( InjuryCause[Cause Grouping] )
)
VAR _Mid =
_Inc * POWER ( 10, _LN )
RETURN
IF (
ISBLANK ( [Count Frequency] ),
BLANK (),
_Pre + _Mid
+ RANKX ( ALLSELECTED ( InjuryCause[Cause Grouping] ), [Ref],, ASC, SKIP )
)
If you now create the clustered column chart with the default options, adding filters to the filter pane to limit the cities, you can get what you are looking for, albeit it isn't particularly pretty:
If you prefer, you can create a more appealing visual as follows (albeit it might require maintenance, because we need to create a separate table for the legend colours which means if the dataset grows in cause groupings, you will need to update the legend table accordingly)
I've created the legend colour code using DAX as follows:
Legend colour code =
ADDCOLUMNS (
SELECTCOLUMNS (
DISTINCT ( InjuryCause[Cause Grouping] ),
"Lengend Case Grouping", InjuryCause[Cause Grouping],
"Index",
RANKX (
VALUES ( InjuryCause[Cause Grouping] ),
InjuryCause[Cause Grouping],
,
ASC
)
),
"Colour Code",
SWITCH (
[Index],
1, "#0065A2",
2, "#99E3F8",
3, "#F98A3C",
4, "#605F61",
5, "#379810",
6, "#C635A7",
7, "#B90000",
8, "#004B82",
9, "#03B1E4",
10, "#DFBFBF",
11, "#9C4102",
12, "#5F6B6D",
13, "#FB8281",
14, "#D4F6C6",
15, "#4B3FF0",
16, "#A4DDEE",
17, "#B69ECD",
18, "#B687AC",
19, "#28738A",
20, "#E6E6E6",
21, "#168980",
22, "#293537",
23, "#BB4A4A",
24, "#F2F549",
25, "#939600"
)
)
So the problem with this method is that if new "Case groupings" appear, you need to update and add new colour codes in the switch function.
The model is now as follows:
You can now create the same column chart as the default, but leave out the legend. You can use the following measure for the conditional formatting of the columns:
Colour legend =
LOOKUPVALUE (
'Legend colour code'[Colour Code],
'Legend colour code'[Lengend Case Grouping], MAX ( InjuryCause[Cause Grouping] )
)
Create a separate legend using a matrix visual as follows (you will need this measure to filter the values in the legend):
Filter Legend =
VAR _Table =
ADDCOLUMNS (
SUMMARIZE (
LossRunToExcel,
LossRunToExcel[Reporting Location City],
'InjuryCause'[Cause Grouping]
),
"@Rows",
IF (
CALCULATE (
RANKX (
ALL ( LossRunToExcel[Reporting Location City] ),
CALCULATE ( [Count Frequency], ALL ( InjuryCause[Cause Grouping] ) ),
,
DESC,
SKIP
),
ALL ( 'Legend colour code'[Lengend Case Grouping] )
) < 6
&& [Top 5 by frequency and Incurred] < 6
&& NOT ISBLANK ( [Count Frequency] ),
1
)
)
RETURN
COUNTROWS (
CALCULATETABLE (
VALUES ( 'InjuryCause'[Cause Grouping] ),
FILTER ( _table, NOT ISBLANK ( [@Rows] ) )
)
)
Make sure "Maintain layer order is "on" under properties in the formatting pane - it will keep the legend visible once published even if you click on the chart.
And the visual will be interactive based on a selection in the legend:
New file attached
I got the first example to work in main file. Thank you for all the help. I will need more time this weekend to try the more creative and visual 2nd option.
- bdehning3 years agoPost Prodigy
Now whats funny it that the Table gets different cities than the visual in my main file. I may need to take your new visual measures and apply them to the table.
- bdehning3 years agoPost Prodigy
See table and chart. Shiloh is wrong on table and Frisco is right on Visual. Frisco is 28 and Shlioh is 27 I mentioned there was an issue with the table yesterday for some accounts.
- bdehning3 years agoPost Prodigy
Ok now I think I am good. I applied fhe new Sum Measure from chart to table.
- bdehning3 years agoPost Prodigy
Here is what Chart look like when published?
Not sure why it looks good before publihing and not after? Why is it doing that?
- bdehning3 years agoPost Prodigy
How would we remove the City Name from the Axis and still keep sorting by City and Cause Grouping for it to publish right?
- PaulDBrown3 years agoCommunity Champion
Did my post with 2 examples of the clustered column chart disappear?
- PaulDBrown3 years agoCommunity Champion
If you remove the city field, the measures loose the field context, so the visual will display aggredate values for case grouping
- bdehning3 years agoPost Prodigy
Paul, how would you tweak the following you provided to make page where Sum is used first and Count is as Tie breaker. I tried to replace Count with Sum for all and got close.
Ref =VAR _MX =MAXX (ALL ( InjuryCause[Cause Grouping] ),CALCULATE ( SUM ( LossRunToExcel[Total Gross Incurred] ) ))VAR _LNGTh =LEN ( FORMAT ( INT ( _MX ), "Text" ) ) + 1RETURNCOUNT ( LossRunToExcel[Total Gross Incurred] ) * POWER ( 20, _LNGTh )+ SUM ( LossRunToExcel[Total Gross Incurred] )Sort measure Count Location Cause =VAR _FreqByCity = CALCULATE([Count of Total Gross Incurred], FILTER(ALL(InjuryCause[Cause Grouping]), [Top 5 by frequency and Incurred]<6))VAR _LN = LEN(FORMAT(CALCULATE([Count of Total Gross Incurred], ALL('LossRunToExcel'[Reporting Location City])), "text"))VAR _Pre = _FreqByCity *POWER(10, _LN*2)VAR _Inc = CALCULATE(RANKX(ALLSELECTED(LossRunToExcel[Reporting Location City]), [Sum of Total Gross Incurred],,ASC,Dense), ALLSELECTED(InjuryCause[Cause Grouping]))VAR _Mid = _Inc * POWER(10, _LN)RETURNIF(ISBLANK([Count of Total Gross Incurred]), BLANK(), _Pre + _Mid + RANKX(ALLSELECTED(InjuryCause[Cause Grouping]),[Ref],,ASC,Skip))Top 5 by frequency and Incurred =IF (ISBLANK ( [Sum of Total Gross Incurred] ),BLANK (),RANKX ( ALL ( InjuryCause[Cause Grouping] ), [Ref],, DESC, SKIP ) - bdehning3 years agoPost Prodigy
I believe I got it work. I had to recheck all.