Forum Discussion
Can I define a custom column variable based on a text search slicer value?
- Anonymous2 years ago
Hi lsealy ,
I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:
1. Add index column in Power Query Editor
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtM30TcyMDJR0lEy0vU0NtF1ArKCgdizpKICRRDBMjY1UPBWMDTSM1VwC1FwzEtWCE/MyQFKmFuY65kqxeqAjDU0RJjram6GaS5MENVcLy+gwQppJTAjdQ1NTAxgRhoRcCp2Iw0NQObBDLQ0o9A4dBeaAY2gqoFGlHoY3UBDCwoNxBrZRqa0MNXMCJSCYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ActionDate = _t, Job = _t, Action = _t, ItemType = _t, From = _t, To = _t, ICODE = _t, #"Barrier Feet" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ActionDate", type date}, {"Job", type text}, {"Action", type text}, {"ItemType", type text}, {"From", type text}, {"To", type text}, {"ICODE", type text}, {"Barrier Feet", type number}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Job", "ItemType"}, {{"Index", each Table.AddIndexColumn(_, "Index",1,1), type table }}), #"Expanded Index" = Table.ExpandTableColumn(#"Grouped Rows", "Index", {"ActionDate", "Action", "From", "To", "ICODE", "Barrier Feet", "Index"}, {"ActionDate", "Action", "From", "To", "ICODE", "Barrier Feet", "Index"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Index",{{"Job", type text}, {"ItemType", type text}, {"Action", type text}, {"From", type text}, {"To", type text}, {"ICODE", type text}, {"Barrier Feet", type number}, {"Index", Int64.Type}, {"ActionDate", type date}}) in #"Changed Type1"2. Create a measure as below
RT = VAR _index = SELECTEDVALUE ( crf38_fieldactions[Index] ) VAR _job = SELECTEDVALUE ( crf38_fieldactions[job] ) VAR _date = SELECTEDVALUE ( crf38_fieldactions[ActionDate] ) VAR FilteredTable = FILTER ( ALLSELECTED ( crf38_fieldactions ), crf38_fieldactions[Job] = _job && crf38_fieldactions[Index] <= _index && crf38_fieldactions[ActionDate] <= _date ) RETURN IF ( SELECTEDVALUE ( crf38_fieldactions[Barrier Feet] ) <> 0 && NOT ( ISBLANK ( SELECTEDVALUE ( crf38_fieldactions[Barrier Feet] ) ) ), CALCULATE ( SUM ( crf38_fieldactions[Barrier Feet] ), FilteredTable ) )3. Create a table visual and add index field onto the table visual
Best Regards
4 Replies
- rajendraongole1
Super User
Hi lsealy - Can you try with below measure instead of using a calculated column
Modified measure:
Measure_Result =
VAR CurrentDate = MAX(crf38_fieldactions[ActionDate])
VAR SelectedSearchText = SELECTEDVALUE(crf38_fieldactions[FromTo])VAR FilteredTable =
FILTER(
ALL(crf38_fieldactions),
crf38_fieldactions[ActionDate] <= CurrentDate &&
crf38_fieldactions[ActionDate] >= MIN(crf38_fieldactions[ActionDate]) &&
SEARCH(SelectedSearchText, crf38_fieldactions[FromTo], 1, 0) > 0 &&
crf38_fieldactions[ItemType] = MAX(crf38_fieldactions[ItemType])
)RETURN
IF(
MAX(crf38_fieldactions[Barrier Feet]) <> 0 && NOT(ISBLANK(MAX(crf38_fieldactions[Barrier Feet]))),
CALCULATE(SUM(crf38_fieldactions[Barrier Feet]), FilteredTable)
)Correctly include rows where the job number appears in any of the Job, From, or To columns based on slicer selection.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!- lsealyFrequent Visitor
rajendraongole1 thank you so much. I think I need to use a calculated column instead of a measure, because I need the calculation to occur on each data row. I did paste your formula into a measure and received these results:
- rajendraongole1
Super User
Hi lsealy - Yes, please create a calculated column and test the values.
By using the SELECTEDVALUE function to get the job number from the slicer and the SEARCH function to check for its presence in the FromTo column. check it and let know.
I hope it works.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!