Hi, i have a table with 4 fields and i want to Group By 3 of them and the 4th field has values of {"CM","PM","TOB"} and i want to Count each of them related to the Grouping. How can i apply this please ?
Solved! Go to Solution.
Hello
check out this approach. It uses Table.Group and a special function to count your specific items.
Use this variable to input your items to be counted
ItemsToCount = {"CM", "PM", "TOB"},
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSgWNnX6VYHVShAHKFQvydMMSg5icBmTAcgCkE1BmTB9OOJkGMfpAtsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
#"Grouped Rows" = Table.Group
(
#"Changed Type",
{"Column1", "Column2", "Column3"},
{
{
"Count",
(tbl)=>
let
ItemsToCount = {"CM", "PM", "TOB"},
CountItems = Text.Combine(List.Transform(ItemsToCount, (trans)=> trans &": " & Text.From(List.Count(List.Select(tbl[Column4],each _ = trans)))), ", ")
in
CountItems
}
}
)
in
#"Grouped Rows"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi, @Mamr
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Result =
var cm =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="CM"
)
),0
)
var pm =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="PM"
)
),0
)
var tob =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="TOB"
)
),0
)
return
"CM:"&cm&" PM:"&pm&" TOB:"&tob
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Mamr
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Result =
var cm =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="CM"
)
),0
)
var pm =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="PM"
)
),0
)
var tob =
COALESCE(
COUNTROWS(
FILTER(
'Table',
[WoType]="TOB"
)
),0
)
return
"CM:"&cm&" PM:"&pm&" TOB:"&tob
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi shawou459 , thank you for your reply, here is a screenshoot for my power bi desktop interface.
@Mamr , DAX is born for such a statistical job. It's only a matter of several drag-n-drop into a matrix viz. It takes 10 seconds only; then you can sit back and relax...
Hello
check out this approach. It uses Table.Group and a special function to count your specific items.
Use this variable to input your items to be counted
ItemsToCount = {"CM", "PM", "TOB"},
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSgWNnX6VYHVShAHKFQvydMMSg5icBmTAcgCkE1BmTB9OOJkGMfpAtsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
#"Grouped Rows" = Table.Group
(
#"Changed Type",
{"Column1", "Column2", "Column3"},
{
{
"Count",
(tbl)=>
let
ItemsToCount = {"CM", "PM", "TOB"},
CountItems = Text.Combine(List.Transform(ItemsToCount, (trans)=> trans &": " & Text.From(List.Count(List.Select(tbl[Column4],each _ = trans)))), ", ")
in
CountItems
}
}
)
in
#"Grouped Rows"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI โ
Join digitally, March 2โ4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!
User | Count |
---|---|
63 | |
34 | |
27 | |
20 | |
8 |
User | Count |
---|---|
65 | |
45 | |
38 | |
32 | |
19 |