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
rohithkothaneth
Resolver I
Resolver I

Issue in using FIRSTDATE and MIN &MINX in DAX measure

Hello,

I'm trying to find the StartDate and EndDate selected using the date slicer which is looking at a Data Table.  Use this date in a DAX measure to find the count of case numbers based on case type.

 

Below two columns are added to the same table based on the below formula

 

DateOpened = [Opened At].[Date]

DateClosed = [Closed At].[Date]

 

 

Here is my sample data:

TypeOpened AtClosed At
Type 11/19/2021 17:51 
Type 21/5/2022 10:221/5/2022 12:22
Type 31/18/2022 19:38 
Type 27/19/2022 7:357/20/2022 11:26
Type 311/23/2022 23:3711/24/2022 11:28
Type 33/9/2023 0:493/10/2023 11:34
Type 19/19/2022 1:259/20/2022 16:53
Type 21/31/2023 4:58 
Type 311/7/2022 6:04 
Type 24/8/2019 8:234/8/2019 0:23
Type 112/28/2021 1:3612/28/2021 10:36
Type 14/16/2019 17:524/16/2019 22:52

 

Below is my measure which is returning blank rows

 

Beginning Balance =
var thisType = "Type 2"
var thisPeriodBegin = FIRSTDATE('_Dates'[Date])
var thisPeriodEnd = LASTDATE('_Dates'[Date])

var filtered = FILTER('Cases',
'Cases'[Type] = thisType
&&
('Cases'[DateOpened] < thisPeriodBegin)
&&
('Cases'[DateClosed] = blank() || 'Cases'[DateClosed] >= thisPeriodBegin)
)
var total = FILTER('Cases',
('Cases'[DateOpened] < thisPeriodBegin)
&&
('Cases'[DateClosed] = blank() || 'Cases'[DateClosed] >= thisPeriodBegin)
)

return if( (thisType = "Total"),
CALCULATE(COUNTROWS(total)),
CALCULATE(COUNTROWS(filtered))
)

 

I'm getting issue with the FIRSTDATE calculation, though if I try to return the result of the firstdate in a card visual, it is returning the correct firstdate selected per the date slicer. I tried MIN & MINX instead of FIRSTDATE and I'm getting the same result as BLANK ROW.

 

Tried to comment the ('Cases'[DateOpened] < thisPeriodBegin && within the "Filtered" & ('Cases'[DateOpened] < thisPeriodBegin && within the "Total" veriables and then Im getting the results as I needed.  

 

Did I missed anything here? Any help in getting this issue resolved is really appreciated.

 

Thanks,

Rohith 

4 REPLIES 4
rohithkothaneth
Resolver I
Resolver I

Unfortunately Im not able to find anything in the onedrive. I believe this could be a restriction on my client laptop.  Please see the screenshot below.

 

rohithkothaneth_0-1683639689684.png

 

Anyways I was able to find a solution to my issue, the filter on the date table was restricting to look date less than the selected date slicer data.  Since I couldn't download the file, not sure if that was the approach you took in your pbix file.

 

Beginning Balance =

var thisType = "Type 2"

var thisPeriodBegin = FIRSTDATE('_Dates'[Date])

var thisPeriodEnd = LASTDATE('_Dates'[Date])

 

RETURN if( (thisType = "Total"),
CALCULATE(COUNTROWS(
FILTER('Cases',
'Cases'[DateOpened] < thisPeriodBegin
&&
('Cases'[DateClosed] = blank() || 'Cases'[DateClosed] >= thisPeriodBegin )
)
), REMOVEFILTERS('_Date Opened')
),
CALCULATE(COUNTROWS(
FILTER( 'Cases',
'Cases'[Type] = thisType
&&
('Cases'[DateOpened] < thisPeriodBegin)
&&
('Cases'[DateClosed] = blank() || 'Cases'[DateClosed] >= thisPeriodBegin)
)
), REMOVEFILTERS ('_Date Opened')
)
)
rohithkothaneth
Resolver I
Resolver I

Thank you @Ashish_Mathur for youe response.  Unfourtunately i'm not able to download the PBI file form the onedrive. When I opened the link the drive is empty.

 

Could you please show me the chnages at the measure that worked for you?

Hi,

The file is there.  See the screenshot.  There are many steps so cannot write the down.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.

Top Kudoed Authors