Forum Discussion
Need help for matrix view
Hi Community members,
I need your help to buiId a matrix view shown as: for goal g1
| year | jan | feb | mar | apr | may | jun | july | aug | sep | oct | nov | dec | YTD | target |
| 2020 | 1 | 3 | 5 | 6 | 9 | 11 | 14 | 14 | 16 | |||||
| 2019 | 1 | 2 | 4 | 5 | 6 | 8 | 10 | 11 | 12 | 13 | 13 | 15 | 15 | 15 |
I tried but it shows target for each month which is undesirable.
here the YTD is the actual_score for latest month or month=-2 and
target is the value from target column where month=-2 or it can be the average of target for all months.
Please help me out to solve this.
Thanks,
Arundhati
My demo data is as
| year | monthid | goal | score | taget |
| 2020 | -2 | g1 | 14 | 16 |
| 2020 | 1 | g1 | 1 | 16 |
| 2020 | 2 | g1 | 3 | 16 |
| 2020 | 3 | g1 | 5 | 16 |
| 2020 | 4 | g1 | 6 | 16 |
| 2020 | 5 | g1 | 9 | 16 |
| 2020 | 6 | g1 | 11 | 16 |
| 2020 | 7 | g1 | 14 | 16 |
| 2019 | -2 | g1 | 15 | 15 |
| 2019 | 1 | g1 | 1 | 15 |
| 2019 | 2 | g1 | 2 | 15 |
| 2019 | 3 | g1 | 4 | 15 |
| 2019 | 4 | g1 | 5 | 15 |
| 2019 | 5 | g1 | 6 | 15 |
| 2019 | 6 | g1 | 8 | 15 |
| 2019 | 7 | g1 | 10 | 15 |
| 2019 | 8 | g1 | 11 | 15 |
| 2019 | 9 | g1 | 12 | 15 |
| 2019 | 10 | g1 | 13 | 15 |
| 2019 | 11 | g1 | 13 | 15 |
| 2019 | 12 | g1 | 15 | 15 |
| 2020 | -2 | g2 | 10.2 | 11 |
| 2020 | 1 | g2 | 1.1 | 11 |
| 2020 | 2 | g2 | 2.3 | 11 |
| 2020 | 3 | g2 | 4.5 | 11 |
| 2020 | 4 | g2 | 5 | 11 |
| 2020 | 5 | g2 | 6.1 | 11 |
| 2020 | 6 | g2 | 8.1 | 11 |
| 2020 | 7 | g2 | 10.2 | 11 |
| 2019 | -2 | g2 | 10 | 11 |
| 2019 | 1 | g2 | 1.3 | 11 |
| 2019 | 2 | g2 | 2.3 | 11 |
| 2019 | 3 | g2 | 3.5 | 11 |
| 2019 | 4 | g2 | 5.7 | 11 |
| 2019 | 5 | g2 | 6 | 11 |
| 2019 | 6 | g2 | 6.4 | 11 |
| 2019 | 7 | g2 | 7.3 | 11 |
| 2019 | 8 | g2 | 8.1 | 11 |
| 2019 | 9 | g2 | 8.4 | 11 |
| 2019 | 10 | g2 | 9 | 11 |
| 2019 | 11 | g2 | 9.1 | 11 |
| 2019 | 12 | g2 | 10 | 11 |
- Anonymous6 years ago
Hi Anonymous ,
You can make transformations in Power Query Editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdJLFoMgDAXQvTC2HBL+a/E47v53UIUSxAdOMugVyEuz74oNG7WpD5/lS2chd5Wgjk2QxIDkmAWyjTyQaxSAfKMMFKQN7CPO26c8ZvO13HDMNpAcYyDJ5oAkG74l2QKQZEtAPZoBS+NIBsti2H+5qqJFpDdcDPO2ReU5o7le9dyj8rMmQDnK2gLahk57QNcQyTcKkxdDwzTBuEpyWymWP4VgpWpMC7iK2dfqQjvG7ItVYuoI2IMCScygHaDEjJN20mJAfb0q4rV1v/j/2cNkPnlyLeFkjx8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [year = _t, monthid = _t, goal = _t, score = _t, taget = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"year", Int64.Type}, {"monthid", Int64.Type}, {"goal", type text}, {"score", type number}, {"taget", Int64.Type}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([goal] = "g1")), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"monthid", type text}}, "zh-CN"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"monthid", type text}}, "zh-CN")[monthid]), "monthid", "score", List.Sum), #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"-2", "YTD"}}), #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"goal"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"year", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "YTD", "taget"}), #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"year", Order.Descending}}) in #"Sorted Rows"Best Regards
Rena
5 Replies
- amitchandakSuper User
Anonymous , You have to is using some calculated table. The hybrid table is not possible as of now.
I created an idea, vote for that.https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/39773011-hybrid-table
- AnonymousNot applicable
Hi Amit,
Can you please share .pbix file to learn more .
- andreMemorable Member
you need to create a table with these values in a single column:
jan feb mar apr may jun july aug sep oct nov dec YTD target that colum of that table will go into the columns for your matrix. then you need to write a new smart calc that woudl look at the value of the column and then calculate the proper value for the cell. so you would have a switch() statement with 14 different conditions to check.
or you could do it with a calculation group, you would not need a swith statement
- AnonymousNot applicable
Hi Anonymous
You can use this measure over values in your matrix visual.Target = SWITCH( TRUE() , ISINSCOPE('Table'[monthid]), SUM('Table'[score]) , MAX('Table'[taget]) )Then change Column Subtotal Label to Target.
Appreciate with Kudos.
Please mark as solution if this resolves your problem.
Thanks
- AnonymousNot applicable
Hi Anonymous ,
You can make transformations in Power Query Editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdJLFoMgDAXQvTC2HBL+a/E47v53UIUSxAdOMugVyEuz74oNG7WpD5/lS2chd5Wgjk2QxIDkmAWyjTyQaxSAfKMMFKQN7CPO26c8ZvO13HDMNpAcYyDJ5oAkG74l2QKQZEtAPZoBS+NIBsti2H+5qqJFpDdcDPO2ReU5o7le9dyj8rMmQDnK2gLahk57QNcQyTcKkxdDwzTBuEpyWymWP4VgpWpMC7iK2dfqQjvG7ItVYuoI2IMCScygHaDEjJN20mJAfb0q4rV1v/j/2cNkPnlyLeFkjx8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [year = _t, monthid = _t, goal = _t, score = _t, taget = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"year", Int64.Type}, {"monthid", Int64.Type}, {"goal", type text}, {"score", type number}, {"taget", Int64.Type}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([goal] = "g1")), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"monthid", type text}}, "zh-CN"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"monthid", type text}}, "zh-CN")[monthid]), "monthid", "score", List.Sum), #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"-2", "YTD"}}), #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"goal"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"year", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "YTD", "taget"}), #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"year", Order.Descending}}) in #"Sorted Rows"Best Regards
Rena