Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Custom MQuery Column -populate a (conditioned) value for as long as another column has repeated rows

Hi,

 

I'm trying to break out and classify my data so I can make several slicers to slice a particular data column. However, the data for my slicers is all contained in 2 columns: a key column which classifies the type of data (ie, slicer header); and a value column which gives the corresponding value (the slicer dropdown options). The data is structured such that I have some result number I want to plot which has some number of entries in the key, value columns which provide context about the measurment. So the result entry repeats for as many key, value entries there are and then a new result will start repeating for the next run of data (1 number, many entries).

 

What I'd like to do is split out the key, value columns into separate columns depending on key type. However, when I use a conditional column, I get a bunch of null entries which means I can't slice on more than 1 value at a time. What I want is to have that column repeat the entry until the next run begins, each run can be classified by a run ID column. Right now my conditional column says something like:

 

 

if column = key and entry = name, then return corresponding value

 

 

 

I guess I want to condition it further to continue repeating if the Run ID is the same, until it's not and the next run starts. Is this possible? I've attached a picture for reference. Thanks!

 

want vs have.png

 

 

 

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous -

 

This seems like a possible solution.

 

2.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLVMzCwUNJR8kvMTQVSXvkZeXmVQEZwSVFmXrohshAIxeog6XFMB2kxMUJRDhNBVeqempeSWgRk+CbmpKKrhwmDdVjqGRoYIRwUnJFYmgfXYIQkArcDpgPiHCNTFNUwEVSlcOe4peYiO8gI7iCoRGwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Some Result" = _t, Key = _t, Value = _t, Run = _t, Name = _t, Age = _t, Gender = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Some Result", type number}, {"Key", type text}, {"Value", type text}, {"Run", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Gender", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Name", "Gender"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"Name"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Gender"}),
    #"Grouped Rows" = Table.Group(#"Filled Up", {"Some Result"}, {{"Grouped", each _, type table [Some Result=number, Key=text, Value=text, Run=text, Name=text, Age=number, Gender=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Sort([Grouped],{{"Age",Order.Descending}})),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Some Result", "Key", "Value", "Run", "Name", "Age", "Gender"}, {"Some Result.1", "Key", "Value", "Run", "Name", "Age", "Gender"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Grouped", "Some Result.1"}),
    #"Filled Down1" = Table.FillDown(#"Removed Columns",{"Age"})
in
    #"Filled Down1"

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

1 REPLY 1
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous -

 

This seems like a possible solution.

 

2.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLVMzCwUNJR8kvMTQVSXvkZeXmVQEZwSVFmXrohshAIxeog6XFMB2kxMUJRDhNBVeqempeSWgRk+CbmpKKrhwmDdVjqGRoYIRwUnJFYmgfXYIQkArcDpgPiHCNTFNUwEVSlcOe4peYiO8gI7iCoRGwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Some Result" = _t, Key = _t, Value = _t, Run = _t, Name = _t, Age = _t, Gender = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Some Result", type number}, {"Key", type text}, {"Value", type text}, {"Run", type text}, {"Name", type text}, {"Age", Int64.Type}, {"Gender", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Name", "Gender"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"Name"}),
    #"Filled Up" = Table.FillUp(#"Filled Down",{"Gender"}),
    #"Grouped Rows" = Table.Group(#"Filled Up", {"Some Result"}, {{"Grouped", each _, type table [Some Result=number, Key=text, Value=text, Run=text, Name=text, Age=number, Gender=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Sort([Grouped],{{"Age",Order.Descending}})),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Some Result", "Key", "Value", "Run", "Name", "Age", "Gender"}, {"Some Result.1", "Key", "Value", "Run", "Name", "Age", "Gender"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Grouped", "Some Result.1"}),
    #"Filled Down1" = Table.FillDown(#"Removed Columns",{"Age"})
in
    #"Filled Down1"

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.