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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
KarenKazab
Frequent Visitor

DAX Measure for counting per month of a year from a date entered slicer

Hi all,

 

Need some help with a measure, can't quite work out how to tackle it

 

I have a date table with no relationship to the main fact table of void and let properties, the user uses a date slicer (from the date table) to choose one date and the below measure uses this date entered to work out on that date what was vacant at that point in time. I need to be able to work out using the same date entered through the slicer what would have been the vacant stock at each month prior to the date entered up to a year i.e. if entered today (3rd August 2021) then what was vacant at 3rd July/3rd June/3rd May and so on up to a year. I could do a measure for each month seperately but then how could that display easily on a line graph trend for a year?

 

Measure for vacant stock count at point in time entered via date slicer:

Count Vacant Stock =
VAR vEnd = MAX('Date'[Date])
RETURN
CALCULATE(
COUNT('Occupied Vacant Stock At Date'[Tenancy Number]),
FILTER ('Occupied Vacant Stock At Date',
'Occupied Vacant Stock At Date'[TenancyCommencementDate] <= vEnd &&
('Occupied Vacant Stock At Date'[TenancyTerminationNoNulls] >= vEnd &&
'Occupied Vacant Stock At Date'[DisposedDateNoNulls] >vEnd &&
'Occupied Vacant Stock At Date'[PropertyHandoverDate2] <=vEnd &&
NOT(ISBLANK('Occupied Vacant Stock At Date'[PropertyHandoverDate2]))
&& 'Occupied Vacant Stock At Date'[Occupied Status] ="Vacant"
)
))
5 REPLIES 5
KarenKazab
Frequent Visitor

Hi thanks that helps a bit in order to get the range of dates available but I need to be able to count for each month, i.e. a property may be vacant across multiple months, so at one point of each month depending on which day they enter i.e. the end of the month it would need to calculate for each end of month for the following year.

Here is what the data would look like, so checking three date columns to see if they were vacant across each month of the year based upon the date slicer the user enters. So I would then have a line chart to show the count of vacancies and a month/year on the vertical axis to show a trend of vacant properties across the months of the year. Below based upon if the user entered the 30/05/2021 (so the range would be 30/05/2020 - 30/05/2021)

SeqAddressProperty Handover DateVoid Start DateVoid End DateDec 2020 Vacant CountJan 2021 Vacant CountFebMarchAprilMay
1Add 130/01/202130/01/202101/06/2021011111
2Add 227/02/202127/02/202101/03/2021001000
3Add 3 30/01/202130/01/202101/03/2021011000
4Add 420/06/202130/06/202120/08/2021000000
5Add 5 30/01/202030/01/202030/03/2020000000
6Add 620/08/202020/01/202030/08/2021111111
    Total Vacant Per Month134222

Hi @KarenKazab ,

 

Thanks for the data. I'm a little confused about the data you've provided above. Is it a table or visual?

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Its a bit of both, what the data looks like and then what I would expect the count to be for each row to display what would be expected. 

I am pretty much there with the DAX now, except I have had to do month end counts which is ok not exactly what I wanted to achieve but it'll do, the only thing I need to add is another filter on the date table based upon the commented out var filterdate but not sure where to add that.


Count Vacant Stock Year 3 date =
VAR vEnd = MAX('Date'[Date])
var _firstStartDate = date(year(vEnd)-1,month(vEnd),day(vEnd))
//var filterdate =
//FILTER('Date', 'Date'[Date] >=_firstStartDate && 'Date'[Date] <=vEnd)
var _currDate=SELECTEDVALUE('Date'[EndOfMonth])

var _vacantprops=

FILTER(
'Occupied Vacant Stock At Date',
'Occupied Vacant Stock At Date'[TenancyCommencementDate] <=_currDate &&
'Occupied Vacant Stock At Date'[TenancyTerminationNoNulls] >=_currDate &&
'Occupied Vacant Stock At Date'[DisposedDateNoNulls] >_currDate &&
'Occupied Vacant Stock At Date'[PropertyHandoverDate2] <=_currDate &&
NOT(ISBLANK('Occupied Vacant Stock At Date'[PropertyHandoverDate2])) &&
'Occupied Vacant Stock At Date'[Occupied Status] ="Vacant"
)

var _countRows=COUNTROWS(_vacantprops)

return

if(_currDate <=TODAY() && _currDate >=_firstStartDate && _currDate <=vEnd,
if(ISBLANK(_countRows),0,_countRows)
)




v-jayw-msft
Community Support
Community Support

Hi @KarenKazab ,

 

Please show some sample data and expected result to us if you need DAX help.

You could check the topic about How-to-Get-Your-Question-Answered-Quickly .

 

Best Regards,

Jay

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@KarenKazab , Use these three

VAR vEnd = MAXX(allselected('Date'),'Date' [Date])
VAR vStart = date(year(vEnd)-1,month(vEnd),day(vEnd))
VAR vDay = day(vEnd)

 

Check for range between vStart  and vEnd end check Day of date = vDay (this will insure same day of each month

)

Like 3rd july, 3rd June etc

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.