Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors