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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Sohan
Helper III
Helper III

Can't filter calculated column

I have the following calculated column, however I cannot seem to filter this data with a slicer. For example, when I try to slice it based on a UserID, it does not provide the correct results, even though there is a relation between FactAppointment[UserID] and DimUser[UserID]. The same holds for FactAppointment[LocationID] and DimLocation[LocationID]. 

Does anyone know how I can resolve this?

 

OWPositionCorrected =
VAR _currentDate = TestTable[Date]
VAR _currentDatePlusSixMonths = EDATE(_currentDate, 6)

RETURN

CALCULATE(
DISTINCTCOUNT(FactAppointment[AppointmentID]),
FILTER(FactAppointment, FactAppointment[Date appointment] >= _currentDate && 
FactAppointment[Date appointment] <= _currentDatePlusSixMonths && 
FactAppointment[Date booking] <= _currentDate)
)

 

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi @Sohan ,

 

Slicers cannot be used in calculated columns.  They can, however, be used in measures.

Slicers are Filters, and thus use filter context.  Filters can change dynamically based on what is selected, and how filter interactions are defined.  Since measures are dynamic fields calculated on demand, they can leverage this filter context to shape results.

 

So, you should use a measure instead of the calculated column if you would like to change the calculation in a table when the slicer value changed. as follows:

 

OWPositionCorrected =
VAR _currentDate = Max(TestTable[Date])
VAR _currentDatePlusSixMonths = EDATE(_currentDate, 6)

RETURN

CALCULATE(
DISTINCTCOUNT(FactAppointment[AppointmentID]),
FILTER(FactAppointment, MAX(FactAppointment[Date appointment]) >= _currentDate && 
MAX(FactAppointment[Date appointment]) <= _currentDatePlusSixMonths && 
MAX(FactAppointment[Date booking] )<= _currentDate)
)

 

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

@v-tangjie-msft When I change it to a measure, the result change and become incorrect. The measure is supposed to count the distinct appointments per row in the calendar table for the coming 6 months, where the booking date may not be larger than than date its calculated for. 

 

Any idea how I can achieve this with a measure?

Hi @Sohan ,

 

There doesn't look like there's anything wrong with the measure formula, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and model relationships and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors