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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
SEMattis
Advocate III
Advocate III

Dynamic Variance Based on Two Date Tables

Hi, 

 

I've spent some time in trying to develop a script that would allow me to create a dynamic variance calculation based on dates from two different tables. The code looks as follows:

 

M_%_VARI =



VAR BaseDate = EOMONTH(SELECTEDVALUE(dim_Date[EndofMonth]),0)
VAR CompDate = EOMONTH(SELECTEDVALUE(dim_ComparisonDate[EndofMonth]),0)

VAR BaseCount = CALCULATE(COUNTA(fact_CoworkerHistory[EmployeeNumber]),
BaseDate = fact_CoworkerHistory[LastDayOfMonth]
)
VAR CompCount = CALCULATE(COUNTA(fact_CoworkerHistory[EmployeeNumber]),
FILTER(fact_CoworkerHistory,fact_CoworkerHistory[LastDayOfMonth] = CompDate)
)
RETURN
CALCULATE((BaseCount - CompCount) / BaseCount)
 
The problem I'm encountering is that the syntax is returning blanks for both the BaseCount and the CompCount which means the variance is also returned as blank. What am I getting wrong here :S ?
 
Many thanks in advance.
1 ACCEPTED SOLUTION

You will need to use ISFILTERED or ISCROSSFILTERED to figure out which of the date tables is filtered.  What if they both are? Worst case you may have to use inactive relationships or disconnected tables.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Sounds very similar to a YoY calculation (apart from the sign).  Could you show the data model?

 

Would you mind showing some sample data and indicate the expected outcome based on that sample data?

@lbendlin 

 

Sure, here's a mock up of the data model:

 

 

DMDM

 

So the expected outcome is to be able to calculate the variance of the number of rows in the fact_CoworkerHistory (Using a snapshot date column) table depending on which of the date tables I use to filter the no of rows.

You will need to use ISFILTERED or ISCROSSFILTERED to figure out which of the date tables is filtered.  What if they both are? Worst case you may have to use inactive relationships or disconnected tables.

@lbendlin many thanks. I'll go ahead and try you proposals

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.