March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Scenario:
Suppose I would like to remove all cells with blank values and then merge rows of each category into one useful row. How will I achieve this requirement?
Sample Data:
Expected Output:
Method1: GroupBy
This method is suitable for few columns.
Method2: Unpivot/Pivot Columns
This method is suitable for many columns.
Method3: Fill Function
This method is suitable for the data that contains cells or rows with blank (null) values.
M Operation in Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQIiYxMzECNWBy4CREYGRob6FvpGBnBx18rUnMo8qAKQoBGGYlNkcXNLTIVKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, A = _t, B = _t, C = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", Int64.Type}, {"A", type text}, {"B", Int64.Type}, {"C", type date}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"A"}),
#"Grouped Rows" = Table.Group(#"Replaced Value", {"Category"}, {{"Count", each Table.FillDown(_,{"A","B","C"}), type table}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"A", "B", "C"}, {"A", "B", "C"}),
#"Grouped Rows1" = Table.Group(#"Expanded Count", {"Category"}, {{"Count", each Table.FillUp(_,{"A","B","C"}), type table}}),
#"Expanded Count1" = Table.ExpandTableColumn(#"Grouped Rows1", "Count", {"A", "B", "C"}, {"A", "B", "C"}),
#"Removed Duplicates" = Table.Distinct(#"Expanded Count1")
in
#"Removed Duplicates"
Method4: Use DAX to create a new table:
New Table=
SUMMARIZE (
'Table',
[Category],
"A", LASTNONBLANK ( 'Table'[A], TRUE () ),
"B", LASTNONBLANK ( 'Table'[B], TRUE () ),
"C", LASTNONBLANK ( 'Table'[C], TRUE () )
)
Output:
Please check the attached file for details.
Hope this article helps everyone with similar questions here.
Author: Eyelyn Qin
Reviewer: Ula Huang, Kerry Wang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.