Forum Discussion
Adding filters to a calculated column
- 8 months ago
Hi eem_2021 ,
If you want to pass slicer or filter value to your visual or calculations, the you can use DAX functions SELECTEDVALUE,HASONEVALUE,FILTERS etc.
these will work with measures not calculated columns .but if you want specific condition rows you can create a measure with flag one or zero.something like below example:
Is Active in Period = VAR PeriodStart = MIN('Date'[Date]) // The start date from your slicer VAR PeriodEnd = MAX('Date'[Date]) // The end date from your slicer VAR EmpStart = SELECTEDVALUE('User Posting'[Start Date]) VAR EmpEnd = SELECTEDVALUE('User Posting'[End Date]) RETURN // Logic: An employee is active if they started before the period ended... // ...AND (they are still active OR they left after the period started). IF ( EmpStart <= PeriodEnd && (ISBLANK(EmpEnd) || EmpEnd >= PeriodStart), 1, 0 )above measure will give me records empstart and empend is withing slicer selection.
If you want to work with calculated columns use string manipulation functions to create the desired columns/flags.
References:
https://community.fabric.microsoft.com/t5/Desktop/Using-measure-as-a-filter/td-p/2996922
https://www.sqlbi.com/articles/applying-a-measure-filter-in-power-bi/
https://learn.microsoft.com/en-us/dax/containsstring-function-dax
https://learn.microsoft.com/en-us/dax/containsstringexact-function-dax
https://learn.microsoft.com/en-us/dax/selectedvalue-function-dax
Please give kudos or mark it as solution once confirmed.
Thanks and Regards,
Praful
Thank you for your reply. I created a visual where I have three columns for profit. The data set I'm using has profit as a text. I am using basic convert () function to make it an integer. However I want to be able to exclude any field that populates that is over 120. I'm running into the issue where I am not able to add filters to calculated columns
Because your Profit field comes in as text, the best approach is to convert it to a proper numeric column in Power Query, then filter out values above 120 directly in the report.
- Convert the column's data type to Decimal Number in Power Query
- Apply the filter to your visual:
Select the visual (table, matrix, chart, etc.)
Go to the Filters pane (on the right)
Drag Profit column into Filters on this visual
Set:
Show items when the value
→ is less than or equal to
→ 120
This will automatically remove any rows where Profit > 120.