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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JCortez
Frequent Visitor

Date Calculation

I have these SQL tables below and I am trying to calculate that date difference between these two columns:

Client_Assessment.clas_date - Client_Program.start_date

I am getting this error below, I am not sure if I am creating the new column in the correct table or why this error is coming up. Any assistance would be greatly appreciated.

 

Capture1.JPGCapture2.JPG

1 ACCEPTED SOLUTION
kushanNa
Super User
Super User

Hi @JCortez 

 

See if this Calculated Column DAX Query helps you 

DateDiff_Days = 
VAR StartDate =
    CALCULATE (
        MIN ( Client_Program[start_date] ),
        FILTER (
            Client_Program,
            Client_Program[client_id] = Client_Assessment[client_id]
                && Client_Program[serv_id] = Client_Assessment[serv_id]
        )
    )
RETURN
IF (
    NOT ISBLANK(StartDate),
    DATEDIFF(StartDate, Client_Assessment[clas_date], DAY),
    BLANK()
)

I have attached a sample PBIX file. I have tested this code and built it without any relationships, since I’m not sure how you have set them up in yours. Feel free to play around with it and see if it works for you as well. 

 

 

View solution in original post

7 REPLIES 7
v-kpoloju-msft
Community Support
Community Support

Hi @JCortez,

Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thanks to @kushanNa@ToddChitt@MasonMA, for those inputs on this thread.

Has your issue is resolved? As provided solution by community members @kushanNa@MasonMA@ToddChitt,

addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Community Forum.

Hi @JCortez,

Hope you had a chance to try out the solution shared earlier. Let us know if anything needs further clarification or if there's an update from your side always here to help.

Thank you.

Hi @JCortez,

Just wanted to follow up one last time. If the shared guidance worked for you, that’s wonderful hopefully it also helps others looking for similar answers. If there’s anything else you'd like to explore or clarify, don’t hesitate to reach out.

Thank you.

kushanNa
Super User
Super User

Hi @JCortez 

 

See if this Calculated Column DAX Query helps you 

DateDiff_Days = 
VAR StartDate =
    CALCULATE (
        MIN ( Client_Program[start_date] ),
        FILTER (
            Client_Program,
            Client_Program[client_id] = Client_Assessment[client_id]
                && Client_Program[serv_id] = Client_Assessment[serv_id]
        )
    )
RETURN
IF (
    NOT ISBLANK(StartDate),
    DATEDIFF(StartDate, Client_Assessment[clas_date], DAY),
    BLANK()
)

I have attached a sample PBIX file. I have tested this code and built it without any relationships, since I’m not sure how you have set them up in yours. Feel free to play around with it and see if it works for you as well. 

 

 

ToddChitt
Super User
Super User

Hello @JCortez 

It looks like you have to go through table PROGRAM LEVEL to get to the other data field. And there is a many-to-many relationship from that table to Client Assessment. So, from the perspective of Client Program, there could be MANY rows that are related. Power BI doesn't know which row to use.

 

Think of it this way: You ask a parent (that has many children), "How much older are you than your child?" They would have to stop and ask, "Which child?"

 

Check that the relationship is truly Many to Many (and understand the ramification if it is). 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





I am getting this if I edit that relationship: Capture3.JPG

MasonMA
Community Champion
Community Champion

Hi @JCortez 

 

Would you want to optimize your model and avoid many-to-many relationship so that you have Client_Program link directly to Client_Assessment through a one-to-many? 

 

Then you can use:

DateDiff =
DATEDIFF (
Client_Assessment[clas_date],
RELATED ( Client_Program[start_date] ),
DAY
)

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.