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
POSPOS
Post Patron
Post Patron

Incorrect values when calculating range

Hi,

I have a requirement to calculate the date difference between two dates (Initial Date and today()) and then categorise them into different buckets 0-45, 46-89,90+

I am getting incorrect values when the difference is null.

Issue: As the Initial Date is blank, the difference between initial date and today is null. But the range is showing as 0-45 as null is being treated as zero.

Sample pbix file is attached here.

 

Can someone please suggest on how to show this range as "Blank" instead of 0-45?

 

Differnece = 
DATEDIFF(data11[Initial Date],TODAY(),DAY)
Range =
IF(data11[Differnece] >=0 && data11[Differnece]<46,"0-45",
IF(data11[Differnece] >45 &&data11[Differnece]<90,"46-90",
IF(data11[Differnece]>89,">90", 
IF(ISBLANK(data11[Differnece]),"Blank"))))

POSPOS_0-1704489393933.png

 


Thank you.

 

1 ACCEPTED SOLUTION
AmiraBedh
Most Valuable Professional
Most Valuable Professional

In your current setup, when the data11[Initial Date] is blank, DATEDIFF returns a null value, which is not correctly handled in your Range calculation. The solution is to first check if data11[Initial Date] is blank before calculating the difference. If it's blank, you should directly assign "Blank" to the range. Otherwise, proceed with the date difference calculation.

 

 

 

Range = 
IF(
    ISBLANK(data11[Initial Date]), 
    "Blank",
    VAR Differnece = DATEDIFF(data11[Initial Date], TODAY(), DAY)
    RETURN
        IF(Differnece >= 0 && Differnece < 46, "0-45",
        IF(Differnece >= 46 && Differnece < 90, "46-90",
        IF(Differnece >= 90, ">90")))
)

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

3 REPLIES 3
AmiraBedh
Most Valuable Professional
Most Valuable Professional

In your current setup, when the data11[Initial Date] is blank, DATEDIFF returns a null value, which is not correctly handled in your Range calculation. The solution is to first check if data11[Initial Date] is blank before calculating the difference. If it's blank, you should directly assign "Blank" to the range. Otherwise, proceed with the date difference calculation.

 

 

 

Range = 
IF(
    ISBLANK(data11[Initial Date]), 
    "Blank",
    VAR Differnece = DATEDIFF(data11[Initial Date], TODAY(), DAY)
    RETURN
        IF(Differnece >= 0 && Differnece < 46, "0-45",
        IF(Differnece >= 46 && Differnece < 90, "46-90",
        IF(Differnece >= 90, ">90")))
)

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

 

@AmiraBedh  - Solution Worked. Thank you.

 

AmiraBedh
Most Valuable Professional
Most Valuable Professional

Welcome 🙂


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

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.