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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
RichOB
Post Patron
Post Patron

DAX to add last day of month in blank End Date column

Hi, using the dog kennel table below, I'm looking for a column/measure that when the End date is blank, it gives me the last date of the month that we are currently in, and puts the number count in Numbe_of_Days_Open, please. Thanks!

 

LocationKennelStart DateEnd DateNumber of Days
Manchester101/04/202410/04/202410
Manchester101/06/202414/06/202414
Manchester128/11/2024  
2 ACCEPTED SOLUTIONS
AnkitaaMishra
Super User
Super User

Hi @RichOB , 
Try below DAX to create a measure: 

Number_of_Days_Open_Measure_withcorrecttotal =
VAR CurrentDate = TODAY()
VAR EndOfMonthDate = EOMONTH(CurrentDate, 0)
VAR StartDate = MAX('Table'[Start Date])
VAR EndDate = MAX('Table'[End Date])
VAR DaysOpen =
    IF(
        ISBLANK(StartDate),
        BLANK(),
        IF(
            ISBLANK(EndDate),
            DATEDIFF(StartDate, EndOfMonthDate, DAY),
            DATEDIFF(StartDate, EndDate, DAY)
        )
    )
RETURN
    IF(
        HASONEVALUE('Table'[Start Date]),
        DaysOpen, 
        BLANK()  
    )
WhatsApp Image 2024-12-11 at 20.44.14.jpeg
Thanks,
Ankita

View solution in original post

Anonymous
Not applicable

Thanks for the reply from AnkitaaMishra , please allow me to provide another insight:

Hi, @RichOB 

AnkitaaMishra 's solution is a good idea for measures.Now, I will provide a solution for calculated columns:

1.Firstly, you need to create the following two calculated columns:

end1 = 
IF ( ISBLANK ( 'Table'[End Date] ), EOMONTH ( TODAY (), 0 ), 'Table'[End Date] )
Number of Days1 = 
IF (
    ISBLANK ( 'Table'[End Date] ),
    DATEDIFF ( 'Table'[Start Date], EOMONTH ( TODAY (), 0 ), DAY ) + 1,
    DATEDIFF ( 'Table'[Start Date], 'Table'[End Date], DAY ) + 1
)

2.Here's my final result, which I hope meets your requirements.

vlinyulumsft_0-1733981010294.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks for the reply from AnkitaaMishra , please allow me to provide another insight:

Hi, @RichOB 

AnkitaaMishra 's solution is a good idea for measures.Now, I will provide a solution for calculated columns:

1.Firstly, you need to create the following two calculated columns:

end1 = 
IF ( ISBLANK ( 'Table'[End Date] ), EOMONTH ( TODAY (), 0 ), 'Table'[End Date] )
Number of Days1 = 
IF (
    ISBLANK ( 'Table'[End Date] ),
    DATEDIFF ( 'Table'[Start Date], EOMONTH ( TODAY (), 0 ), DAY ) + 1,
    DATEDIFF ( 'Table'[Start Date], 'Table'[End Date], DAY ) + 1
)

2.Here's my final result, which I hope meets your requirements.

vlinyulumsft_0-1733981010294.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

AnkitaaMishra
Super User
Super User

Hi @RichOB , 
Try below DAX to create a measure: 

Number_of_Days_Open_Measure_withcorrecttotal =
VAR CurrentDate = TODAY()
VAR EndOfMonthDate = EOMONTH(CurrentDate, 0)
VAR StartDate = MAX('Table'[Start Date])
VAR EndDate = MAX('Table'[End Date])
VAR DaysOpen =
    IF(
        ISBLANK(StartDate),
        BLANK(),
        IF(
            ISBLANK(EndDate),
            DATEDIFF(StartDate, EndOfMonthDate, DAY),
            DATEDIFF(StartDate, EndDate, DAY)
        )
    )
RETURN
    IF(
        HASONEVALUE('Table'[Start Date]),
        DaysOpen, 
        BLANK()  
    )
WhatsApp Image 2024-12-11 at 20.44.14.jpeg
Thanks,
Ankita

Helpful resources

Announcements
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.