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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rjobaan
Frequent Visitor

filter does not work when columns are not selected

I have the following filter created

filter_dates_general =
VAR result =
IF(

SELECTEDVALUE(fct_revenue[Start_Date])>= MIN(dim_calendar[Date])
&&SELECTEDVALUE(fct_revenue[Start_Date])<=MAX(dim_calendar[Date])
||
SELECTEDVALUE(fct_revenue[End_Date])>= MIN(dim_calendar[Date])
&&SELECTEDVALUE(fct_revenue[End_Date])<=MAX(dim_calendar[Date])
||
SELECTEDVALUE(fct_revenue[Start_Date])<= MIN(dim_calendar[Date])
&&SELECTEDVALUE(fct_revenue[End_Date])>=MAX(dim_calendar[Date]),

1,
0)


RETURN result

 

and a between slicer based on date.

i removed the relationship between fct_revenue and dim_calendar for this

when i have a table with region, absence_code, start_date, end_date, and above filter =1

this filter works fine and is showing all regions which fullfil above formula. so within the date range. or even when start and end date are the same its working.

 

But if i create a piechart based on only absence_code its not working anymore because start and end _date are not within the context anymore..

 

So what to do are to adjust that above filter is working for every dimension within dashboard?

 

 

 

1 ACCEPTED SOLUTION
rjobaan
Frequent Visitor

that is not working. finally i find the correct code:

filter_dates_general =
VAR SelectedStartDate = MIN(dim_calendar[Date])
VAR SelectedEndDate = MAX(dim_calendar[Date])
RETURN
CALCULATE(
DISTINCTCOUNT(fct_revenu[DIM_Customer_ID]),
KEEPFILTERS(
(fct_revenu[Start_Date] >= SelectedStartDate && fct_revenu[Start_Date] <= SelectedEndDate) ||
(fct_revenu[End_Date] >= SelectedStartDate && fct_revenu[End_Date] <= SelectedEndDate) ||
(fct_revenu[Start_Date] <= SelectedStartDate && fct_revenu[End_Date] >= SelectedEndDate)
)
)

View solution in original post

4 REPLIES 4
rjobaan
Frequent Visitor

that is not working. finally i find the correct code:

filter_dates_general =
VAR SelectedStartDate = MIN(dim_calendar[Date])
VAR SelectedEndDate = MAX(dim_calendar[Date])
RETURN
CALCULATE(
DISTINCTCOUNT(fct_revenu[DIM_Customer_ID]),
KEEPFILTERS(
(fct_revenu[Start_Date] >= SelectedStartDate && fct_revenu[Start_Date] <= SelectedEndDate) ||
(fct_revenu[End_Date] >= SelectedStartDate && fct_revenu[End_Date] <= SelectedEndDate) ||
(fct_revenu[Start_Date] <= SelectedStartDate && fct_revenu[End_Date] >= SelectedEndDate)
)
)

Kedar_Pande
Community Champion
Community Champion

When you use a pie chart with just the absence_code, the Start_Date and End_Date fields lose context because they are not included in the visual.

 

Adjusted Measure:

filter_dates_general =
VAR minDate = MIN(dim_calendar[Date])
VAR maxDate = MAX(dim_calendar[Date])

RETURN
CALCULATE (
IF (
MAX(fct_revenue[Start_Date]) >= minDate &&
MAX(fct_revenue[Start_Date]) <= maxDate ||
MAX(fct_revenue[End_Date]) >= minDate &&
MAX(fct_revenue[End_Date]) <= maxDate ||
MAX(fct_revenue[Start_Date]) <= minDate &&
MAX(fct_revenue[End_Date]) >= maxDate,
1,
0
),
ALLSELECTED(fct_revenue)
)

You can use this adjusted measure in a visual filter to filter the pie chart, ensuring that it respects the date range and the absence code context.

but now it doesnt taken into account the values of the slicer right?

when i used above filter on the pie-chart  with filter=1 its showing nothing

Thanks for the reply from Kedar_Pande , please allow me to provide another insight:

Hi, @rjobaan 

Based on my testing, I recommend modifying your measure as follows:

filter_dates_general = 
VAR MinDate = MIN(dim_calendar[Date])
VAR MaxDate = MAX(dim_calendar[Date])
VAR result =
    IF(
        (MAX(fct_revenue[Start_Date]) >= MinDate && MAX(fct_revenue[Start_Date]) <= MaxDate) ||
        (MAX(fct_revenue[End_Date]) >= MinDate && MAX(fct_revenue[End_Date]) <= MaxDate) ||
        (MAX(fct_revenue[Start_Date]) <= MinDate && MAX(fct_revenue[End_Date]) >= MaxDate),
        1,
        0
    )
RETURN result

Although in DAX, the && (AND) operator has a higher precedence than the || (OR) operator, it is advisable to ensure each logical condition is correctly enclosed in parentheses for accuracy and readability. This helps avoid any issues with logical operation precedence.

 

Here is my test example:

vlinyulumsft_0-1728464424630.png

vlinyulumsft_1-1728464424631.png

Test results are as follows:

Before using the measure as a filters:

 

vlinyulumsft_4-1728464471224.png

 

After using the measure as a filters:

:

vlinyulumsft_5-1728464471225.png

Currently, no issues have appeared in my test results.

 

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

For questions about uploading data, you can try the following links:

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Solved: How to upload PBI in Community - Microsoft Fabric Community

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.