Skip to main content
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

Frequent Visitor

Get data for current and last month based on date slicer


I am currently working on something which requires me to get data from start of last month to current date  and the data should change based on the month,year selected in slicer. I searched for different ways  but none are giving desired result


example data set

1000d1 2021-11-15



So if we select august 2021 in slicer it should show count of machines as 3 and if nothing is selected in slicer than it should show 2


i do not want to change anything in my date slicer


I am new to powerbi and not able to get anywhere with this problem 

i am currently using a query similar to this



can anybody help me with this ?


Community Support
Community Support

Hi, @sainig546 

If we get data for the last month and the current month, when the slicer is not selected, the count is from November to December, then the result is 2. But when August is selected, why is the count 3 instead of 2?
There is data for July but not for August.


Or what you want to do is accumulate the counts to date?


Could you please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

It makes it easier to give you a solution.

Best Regards,
Community Support Team _ Zeon Zheng

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


sorry that was my mistake it should show 2 if we select august in slicer i.e for july +august

Hi, @sainig546 

Try to create a measure:

Measure = 
var _date=MAX('Calendar'[Date])
var _Count=
return _Count



Please refer to the attachment below for details. Hope this helps.



Best Regards,
Community Support Team _ Zeon Zheng

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

Super User
Super User

@sainig546 , Based on what I got, Try measure like


This month =
var _max = maxx(allselected(Date),Date[Date])
calculate( DISTINCTCOUNT(Table[machine_id]), filter(all('Date'), 'Date'[Date] <=_max))



last month =
var _max = eomonth(maxx(allselected(Date),Date[Date]),-1)
calculate( DISTINCTCOUNT(Table[machine_id]), filter(all('Date'), 'Date'[Date] <=_max))

Hi amit,

Can we somehow check in a measure if there is any value selected in the slicer.

For example in most languages we can give if than statement 1 else statement 2


using that may be we can provide default value for this measure if nothing is selected in slicer and if a date is selected in slicer than it will be given


like if slicer is null than current month else ...

not sure if this is possible here



can we combine the dataset for both current month and last month in a single measure

Also when i am not selecting any month in slicer its not showing correct data .

if there is no date selection in slicer than it should show data for last month + whatever data we have for this month.

I cant change anything in slicer because i am using report level slicer and this requirement is specific to only this measure rest measures will show all data by default 

Helpful resources

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