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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sandeep_sharma
Helper II
Helper II

DAX basis different date columns

Hi,

 

I have 4 columns...as mentioned in the snapshot. I need to count the total number of Items where Expiration date and received date both are smaller as compared to the 15th of previous month (Current month is selected in a slicer. So if in slicer we select Oct, it should compare the expiration and received dats with 15th of Sep). Also, Billed date should either blank or greater then the 1st day of selected  month in slicer.

 

sandeep_sharma_0-1730884698648.png

 

1 ACCEPTED SOLUTION

I think in the EOMONTH you've put 2 instead of -2.

View solution in original post

7 REPLIES 7
johnt75
Super User
Super User

Try

Num items =
VAR SelectedMonth =
    MAX ( 'Date'[Date] )
VAR StartCurrentMonth =
    EOMONTH ( SelectedMonth, -1 ) + 1
VAR MidPrevMonth =
    EOMONTH ( SelectedMonth, -2 ) + 16
VAR Result =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Expiration Date] < MidPrevMonth,
        'Table'[Received Date] < MidPrevMonth,
        'Table'[Billed Date] > StartCurrentMonth
            || ISBLANK ( 'Table'[Billed Date] ),
        REMOVEFILTERS ( 'Date' )
    )
RETURN
    Result

The REMOVEFILTERS is strictly only necessary if you have a relationship from your date table to the fact table.

Also, this assumes that there is one row per item. If that isn't the case then you can replace COUNTROWS with a DISTINCTCOUNT of the id column.

Thanks @johnt75 for the response.

However it is giving an error saying cannot convert value 'Oct' of type text to type date. I have double checked, date in slicer has the date format on it........in the Slicer I am taking only Year and Month in one slicer...please suggest

 

Make sure that you are using the right column in the SelectedMonth variable. Where it says MAX( 'Date'[Date]) that needs to be a column of type date. It doesn't matter which column you use in the slicer.

Thanks @johnt75 

It is now showing some data atleast. But as I go back in the year, it is reducing the numbers which should not be the case....on investigating I found out that for startcurrentmonth variable it is giving me the data of 1/1/25....any idea why?

 

Basically it showing me the date of two months ahead....so if I select nov in slicer then it shows Jan'25 and If I select Jun then it shows Aug'24

I think in the EOMONTH you've put 2 instead of -2.

This is awesome! Thank you so much! it worked!!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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