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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Dax Measurement Assistance

I am in need of assistance. What is the proper dax measurement to obtain the total daily inmate count (number of inmates currently incarcerated) from current date and 5yrs. back, per day. For example:

3-1-2024 - 340

3-2-2024 - 354

3-3-2025 - 342

The dataset includes, "Booking date", "Release Date", "Booking Number", and a Date Table.

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

RossEdwards,

I ended up creating the following measurement on my data table:

ActiveInmatesCount =
VAR CurrentDate = MAX('DimDate'[Date])
RETURN
    CALCULATE(
       DISTINCTCOUNT('PrevFiveYrsJailing'[Booking#]),
        FILTER(
            'PrevFiveYrsJailing',
            'PrevFiveYrsJailing'[BookingDate] <= CurrentDate &&
            (
                ISBLANK('PrevFiveYrsJailing'[ReleaseDate]) ||
                'PrevFiveYrsJailing'[ReleaseDate] > CurrentDate
            )
        )
    )
 
I was getting the same result where the amounts were not as close to the actual numbers I have.  I ended up linking this data table to a date table and making that relationship inactive.  Once I made the relationship inactive between the two tables, the data appears to more accurate.  I'm not sure why the inactive relationship worked, but it did.  I wanted to thank you for your time and assistance, much appreciated!   

 Alvina

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

RossEdwards,

I ended up creating the following measurement on my data table:

ActiveInmatesCount =
VAR CurrentDate = MAX('DimDate'[Date])
RETURN
    CALCULATE(
       DISTINCTCOUNT('PrevFiveYrsJailing'[Booking#]),
        FILTER(
            'PrevFiveYrsJailing',
            'PrevFiveYrsJailing'[BookingDate] <= CurrentDate &&
            (
                ISBLANK('PrevFiveYrsJailing'[ReleaseDate]) ||
                'PrevFiveYrsJailing'[ReleaseDate] > CurrentDate
            )
        )
    )
 
I was getting the same result where the amounts were not as close to the actual numbers I have.  I ended up linking this data table to a date table and making that relationship inactive.  Once I made the relationship inactive between the two tables, the data appears to more accurate.  I'm not sure why the inactive relationship worked, but it did.  I wanted to thank you for your time and assistance, much appreciated!   

 Alvina

RossEdwards
Solution Sage
Solution Sage

Making some guesses about your dataset but this is what came to mind for me.  Use this measure on a visual and it will take the last date in the context.  If its a monthly table, it will be the date at the end of the month. If its a daily table, it will be daily.

Daily Count = var contextDate = MAX('DateTable'[Date])
var output = CALCULATE(
	COUNTROWS('Inmates'),
	ALL('Inmates'),
	FILTER(
		'Inmates',
		'Inmates'[Booking Date] <= contextDate &&
		'Inmates'[Release Date] >= contextDate
	)
)
RETURN
output

 

Anonymous
Not applicable

Thank you for the prompt reply. This is the output.  I was hoping to get a TOTAL count of currently incarcerated inmates, per day.  For example on 3/23 there would have been approximately 350 inmates in jail, that have been been booked in within my time range and have not been released (time range is 5yrs back from current date).

 

Daily Jail Population Count.JPG

I suspect your issue is that you have used "Booking Date" in your visual.  Replace that with the "Date" column from your Calendar table.

Anonymous
Not applicable

Thanks for that information, I have now changed it to the Date of the Date Table. With the same result.  I appreciate the assistance you've provided thus far!

Daily Jail Population Count v2.JPG

Thats really odd.  Lets test if its unexpected behaviour caused by the filter function. Try this version:

Daily Count = var contextDate = MAX('DateTable'[Date])
var output = CALCULATE(
	COUNTROWS('Inmates'),
	ALL('Inmates'),	
	'Inmates'[Booking Date] <= contextDate,
	'Inmates'[Release Date] >= contextDate	
)
RETURN
output
Anonymous
Not applicable

Daily Jail Population Count v3.JPG

 

Seems like that fixed it?

 

I'd also recommend making sure those different statements are on different rows in that measure (Shift + Enter).  Future you will really appreciate it being easier to read 😉

Anonymous
Not applicable

I'm fairly new to PowerBi, so I apologize in advance for the questions.  March 24th is still showing only 3 active inmates, when there were approximately 350.  Am I missing another step?  Yes, thank you for that bit of advice regarding the shift+enter!

 

Its not immediately obvious to me what other factor is coming into play here.  I'm about to log off so i won't be back on until tomorrow.  I'd manually look at your data and run through the code like you are the machine.  Pick a date and manually set filters according to the rules in the code. Perhaps something obvious will stand out to you.

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.

Top Kudoed Authors