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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate variance and input BLANK if a related Date column is blank

I need to calculate the variance between planned days to complete a request and the actual days taken to complete it. Below is a sample from my data : 

 

IDPlanned Start DatePlanned End DateActual Start DateActual Completion Date Planned DaysActual DaysVariance
10115/07/202020/07/202016/07/202021/07/2020660
10217/07/202025/07/202017/07/202029/07/20209134
10320/07/202030/07/202023/07/2020 11  
10430/07/202010/08/202030/07/2020 12  
10502/08/202006/08/202002/08/202005/08/202054-1

 

'Planned days' & 'Actual days' are calculated columns. I am using DATEDIFF to calculate the number of days between the two dates - start date & end date. 

 

Query: If the 'Actual End' date is blank then, how do I get the following results  :

Actual days to display a 'blank'.

Variance to display a 'blank'

I am using the following formula for the Variance column

 

Comp Var2 = IF(ISBLANK(TestWorkFlow[ActualCompletionDate]), " ", CALCULATE(SUM(TestWorkFlow[Actual Days]))- CALCULATE(SUM(TestWorkFlow[Planned Days])))
 
The error message I get is 
Expressions that yield variant data-type cannot be used to define calculated columns.
 
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous Try:

Comp Var2 = 
  IF(
    ISBLANK(TestWorkFlow[ActualCompletionDate]), 
    BLANK(), 
    SUM(TestWorkFlow[Actual Days])- SUM(TestWorkFlow[Planned Days])
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , first of check Planned Days and Actual Days should have data type number

 

Try measure like

sumx(Table,[Planned Days]-coalesce([Actual Days],0))

 

Sum([Planned Days])-coalesce(Sum([Actual Days]),0)

Greg_Deckler
Super User
Super User

@Anonymous Try:

Comp Var2 = 
  IF(
    ISBLANK(TestWorkFlow[ActualCompletionDate]), 
    BLANK(), 
    SUM(TestWorkFlow[Actual Days])- SUM(TestWorkFlow[Planned Days])
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler 

 

I had to tweak the formula a bit and it worked. 

 

Comp Var2 =
IF(
ISBLANK(TestWorkFlow[ActualCompletionDate]),
BLANK(), CALCULATE(SUM(TestWorkFlow[Actual Days]))-CALCULATE(SUM(TestWorkFlow[Planned Days])))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.