Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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?
Solved! Go to Solution.
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)
)
)
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)
)
)
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:
Test results are as follows:
Before using the measure as a filters:
After using the measure as a filters:
:
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 12 | |
| 9 | |
| 5 | |
| 5 |