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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
RichOB
Helper IV
Helper IV

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
Continued Contributor
Continued Contributor

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

v-linyulu-msft
Community Support
Community Support

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
v-linyulu-msft
Community Support
Community Support

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
Continued Contributor
Continued Contributor

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
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.