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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
teflonreis
Frequent Visitor

Calculated columns that outputs the difference in workdays shall only run if there are 2 dates

Hello everyone

 

I have two columns with dates. And have added a calculated date column that gives me the difference between the the dates in working days. So far so good.

CalculatedColumn date1date2
0  
0 5/23/2022
0  
0  
-25/23/2022 
0  
0  
25/30/20226/1/2022
0  

 

However you probably noticed the problem. The calculated column magically makes up differences when there are no data or one date missing. My two columns have lots of empy cells. In case of two empty cells, calculated columns gives me 0-0=0 days.

In case of only one date and one empty cell, if even gives me negatives number of days.

 

I fail at adding a condition such that it only outputs the difference if there really are two date dates.

Since I want to compute the average number of working days in a Report, I get a wrong average (negative number of days).

 

Really am stuck and would appreciate some help. 

 

This is the condition I am thinking about. However never used variables before.

 

 

IF (AND(Table[date1]<>0, Table[date2]<>0), VAR CalculatedColumn, "Error or do nothing and dont go into average measure")

 

 

And this is the CalculatedColumn formula that I currently use. I would make it a VAR Variable and add an IF statement. Again, never done that before.

 

CalculatedColumn =
( DATEDIFF ( Table[date1], Table[date2], DAY ) )
    - INT ( DATEDIFF ( Table[date1], Table[date2], DAY ) / 7 ) * 2
    - IF (
        WEEKDAY ( Table[date2] ) < WEEKDAY ( Table[date1] ),
        2,
        IF (
            OR (
                WEEKDAY ( Table[date2] ) = 7,
                WEEKDAY ( Table[date1] ) = 1
            ),
            1,
            0
        )
    )

 

 

 

 

2 ACCEPTED SOLUTIONS
tamerj1
Community Champion
Community Champion

Hi @teflonreis 
Replace 

AND(Table[date1]<>0, Table[date2]<>0)

with

AND(Table[date1 > 0, Table[date2] > 0)

View solution in original post

4 REPLIES 4
tamerj1
Community Champion
Community Champion

Hi @teflonreis 
Replace 

AND(Table[date1]<>0, Table[date2]<>0)

with

AND(Table[date1 > 0, Table[date2] > 0)

teflonreis_0-1654167282000.png

Hate to be the guy that states the error codes:

Error "Expressions that yield variant data-type annot be used to define calculated columns.

 

Am I on the right path? Or was it a mistake to use variables in a calculated columns to begin with.

@teflonreis 
Just delete the  , ""

Oh that fixed it. Sorry for the stupid questions. 

Many many thanks for the patience and help.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.