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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
gazz9ar
Frequent Visitor

Between 2 dates in FILTER function

Hi there, 

 

I need to filter a table based on a selected MONTH and YEAR,  the user can select multiple months also.

 This is my measure:

 

Total Checks (SINDESC) Filtered =
VAR selectedyear = SELECTEDVALUE(Dates[Año])
VAR selectedmonth = ALLSELECTED(Dates[MonthNum])
return
CALCULATE([Total Checks (SINDESC)];
FILTER(Cobros; Cobros[Fecha Contabilizacion] IN DATESBETWEEN(Cobros[Fecha Contabilizacion];
DATE(selectedyear;selectedmonth;"01");DATE(selectedyear;selectedmonth;"31")));
USERELATIONSHIP(Dates[Date];Cobros[Fecha Vencimiento Cheque]))
 
 
Of course this measure is not working. First problem is, how do i get the last day of the month or months selected? And if the user selects multiple months it will not work.
 
I dont know if i should be using FILTER function to filter a date, but i need to calculate [Total Checks (SINDESC)] within a range of dates.
 
Thanks in advance guys
 
1 ACCEPTED SOLUTION
gazz9ar
Frequent Visitor

Guys the problem was solved in another post  i did.

Link to solution: https://community.powerbi.com/t5/Desktop/Measure-with-multiple-dates/m-p/892328#M427770

 

Thank you so much for the help.

View solution in original post

7 REPLIES 7
gazz9ar
Frequent Visitor

Guys the problem was solved in another post  i did.

Link to solution: https://community.powerbi.com/t5/Desktop/Measure-with-multiple-dates/m-p/892328#M427770

 

Thank you so much for the help.

amitchandak
Super User
Super User

If your date table is joined with your fact/data table. Why do need to filter. If you use month and year slicer from Date table it should work.

What is the logic you need?  EOMONTH, and ENDOFMONTH can be used for the end date of the month. please find the example below to see how it is used

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date Filer],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date Filer],-12,MONTH))))

MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date Filer])))
MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date Filer],-12,MONTH),"8/31")))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I have to Filter because as you can see, im using USERELATIONSHIP after.

 

First, i obtain every record based on month and year selected by the user.

 

Later  i want visualize the SUM of those records based on other date column in the fact table.

 

 

 

 

Hi @gazz9ar ,

Try this one please.

Total Checks (SINDESC) Filtered =
VAR selectedyear =
    SELECTEDVALUE ( Dates[Año] )
VAR selectedmonth =
    ALLSELECTED ( Dates[MonthNum] )
RETURN
    CALCULATE (
        [Total Checks (SINDESC)];
        FILTER (
            Cobros;
            Cobros[Fecha Contabilizacion] >= DATE ( selectedyear; selectedmonth; "01" )
                && Cobros[Fecha Contabilizacion] <= DATE ( selectedyear; selectedmonth; "31" )
        );
        USERELATIONSHIP ( Dates[Date]; Cobros[Fecha Vencimiento Cheque] )
    )

If it doesn't meet your requirement,  Kindly share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

@v-frfei-msft  sorry for spamming you, i just want to be clear

 

Here is a image of what i want to do:

halp.jpg

The table will change as you change the period, and the bar chart should change based on the "Fecha Vencimiento" column too.

 

I dont need the table, is just a visual help


Thanks @v-frfei-msft , sadly it threw an error.  Anyway i tried a measure with the same structure and the problem still in the slicer and the visual.

 

Please check the file, the page is called HERE. (it is in Spanish, but i think you will understand, i left you notes).

 


Pbix File: https://1drv.ms/u/s!AttE7DRi4S6HilwL7h2gEeXlZBF-?e=XIiC7N

 

Thank you.

Here is my measure, that is working.

LAST1.jpg

 It is the SUM of every Check, filtered by month and year. 

 

last2.jpg

Here you can see in a table the  Total for every date in "Fecha Vencimiento Cheque", how should i group by that date in the given visual?

 

NOTE: if i add to the CALCULATE a filter with USERELATIONSHIP, it shows a wrong Total ($1million ), you can check the records.

 

BUT the visual should group by that Date.  Im starting to think it is not possible 😞

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.