Hello Folks!!
As a matter of fact and promised in previous post Power BI : Transform Data into different Format using M-Query with same number of Data rows, this time I comes with an extension of the previous post where we have discussed on how to manage or transfer one format of data into another under the umbrella of Power BI (Post name is mentioned above), this post will even go further and follow no boundaries on the number of rows data has after Header row, i.e. this will overshadow the restriction of number of rows as mentioned in previous post.
As technology grows and time demands, any restriction or limitation in any kind of technology will always degrade the fame of the technology, hence Microsoft too support on NO LIMIT policy, at least this is true in that case.
Sounds quite Interesting !! Indeed ! Let's explore the world of no limitation under the scope of Power BI with the help of our very own example illustrated in previous post.
Let's start the road roller with some illustration.
Requirement :
Resolution :
Obviously, this is not something which can be achieved easily and not a straight forward at all, instead we need to apply few tricks to achieve the goal, who can be better friend in such situation other than M-Query, so let's see how M-Query will helps us to get rid of such bad format of the data and to convert into format that will be easily readable by Power BI.
let
Source = YOUR SOURCE EXCEL,
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ColA", type text}, {"ColB", type text}, {"ColC", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Type", each if ([ColA]=[ColB]) and ([ColB]=[ColC]) then 1 else 0),
#"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type),
#"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each List.Sum(
List.FirstN(
#"Added Index"[Type],
[Index]
)
)),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Type] = 1)),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"ColB", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Custom", "RunningValue"}})
in
#"Renamed Columns"
let
Source = YOUR SOURCE EXCEL,
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ColA", type text}, {"ColB", type text}, {"ColC", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Type", each if ([ColA]=[ColB]) and ([ColB]=[ColC]) then 1 else 0),
#"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type),
#"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each List.Sum(
List.FirstN(
#"Added Index"[Type],
[Index]
)
)),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", Int64.Type}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Custom", "RunningValue"}}),
#"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"RunningValue"}, Dimension, {"RunningValue"}, "Dimension", JoinKind.LeftOuter),
#"Expanded Dimension" = Table.ExpandTableColumn(#"Merged Queries", "Dimension", {"ColB"}, {"ColB.1"}),
#"Renamed Columns1" = Table.RenameColumns(#"Expanded Dimension",{{"ColB.1", "Type Name"}}),
#"Merged Queries1" = Table.NestedJoin(#"Renamed Columns1", {"ColB"}, Dimension, {"ColB"}, "Dimension", JoinKind.LeftAnti),
#"Removed Other Columns" = Table.SelectColumns(#"Merged Queries1",{"ColA", "ColB", "ColC", "Type Name"})
in
#"Removed Other Columns"
* Please replace Source < Source = YOUR SOURCE EXCEL> with your source path in a code above.
Step - 8 - Click OK.
Hurray !!! Here we go, we got the desired result.
Author - Feel free to ask query if you have any query