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

active jobs over time with filters

Please help met to get the active jobs over time, while still able to apply filters on the power bi dashboard (so no hardcoding stuff).

I have the following tables:

VW

JobOpenedDate    JobClosedDate     FilterX     FilterY
03/04/2018            06/06/2019           1              0
21/12/2018            07/11/2019           0              1

DateTimeTable
DateTime

 

I build relationships between

* DateTime and JobOpenedDate

* DateTime and JobClosedDate

I calculated a measure called ExtraJobsPerPeriod, which is based on the following DAX:

ExtraJobsPerPeriod = IF (
ISNUMBER([OpenedJobs] - [ClosedJobs]);
[OpenedJobs] - [ClosedJobs];
0)

The OpenedJobs and ClosedJobs are measures which are calculated as follows:

OpenedJobs = IF (
CALCULATE(COUNT('VW'[JobOpenedDate]);USERELATIONSHIP('VW'[JobOpenedDate];DateTimeTable[DateTime])) > 0;
CALCULATE(COUNT('VW'[JobOpenedDate]);USERELATIONSHIP('VW'[JobOpenedDate];DateTimeTable[DateTime]));
0)

ClosedJobs = IF (
CALCULATE(COUNT('VW'[JobClosedDate]);USERELATIONSHIP('VW'[JobClosedDate];DateTimeTable[DateTime])) > 0;
CALCULATE(COUNT('VW'[JobClosedDate]);USERELATIONSHIP('VW'[JobClosedDate];DateTimeTable[DateTime])); 
0)

If you then plot ExtraJobsPerPeriod over DateTime, you get exactly the number of additional jobs that are active per time period. Now I just want to create a cumulative sum / running total of this measure, but that is where it goes wrong. Please help me to improve the following formula for "RunningTotal", which gives bad results (somehow, it calculates a running total for 1 year only, and then it starts over again....)

 

RunningTotal = SUMX(
FILTER(
    ALL('DateTimeTable');
    AND(DateTimeTable[DateTime].[MonthNo]<=MAX(DateTimeTable[DateTime].[MonthNo]);
    DateTimeTable[DateTime].[YEAR]<=MAX(DateTimeTable[DateTime].[Year]))
    );
[ExtraJobsPerPeriod])

Please help me to fix this RunningTotal DAX formula because it is wrong, and I would be so happy 🙂

4 REPLIES 4
RobbeVL
Impactful Individual
Impactful Individual

Hi there,

I think this will work when you use the lowest date in the hierarchy.

Please give the dax code below a shot.

 

CALCULATE(
	Measure1;
	FILTER(
		ALLSELECTED('Table'[Date]);
		ISONORAFTER('Table'[Date]; MAX('Table'[Date]); DESC)
Anonymous
Not applicable

Thanks for your quick response RobbeVL.

 

Unfortunately, your code is not doing what I want since it leaves gaps where there are no data points. So for some months the data is correct, and for other months it gives 0, instead of the cumulative sum.

RobbeVL
Impactful Individual
Impactful Individual

Hi,

 

Strange.
Any chance you could provide some sort of sample dataset or pbix file ? 

 

Robbe

Anonymous
Not applicable

I think it is because of the relation between tables, specifically between columns Datetime and JobOpenedDate.

 

Suppose we have the following data:

JobOpenedDate       JobClosedDate

21/03/2019               11/10/2019

03/04/2019               11/10/2019

06/06/2019               11/10/2019

29/09/2019               11/10/2019

 

DateTimeTable

01/03/2019

02/03/2019

.......................

29/11/2019

30/11/2019

 

Then the powerbi graph displays the following:

March 2019: 1 Active Job

April 2019: 2 Active Jobs

May 2019: 0 Active Jobs (because no relation between tables can be made)
June 2019: 3 Active Jobs

July 2019: 0 Active Jobs (because no relation between tables can be made)

August 2019: 0 Active Jobs (because no relation between tables can be made)

September 2019: 4 Active Jobs

October 2019: 0 Active Jobs (because no relation between tables can be made, but in this case it is actually correct!)

 

So when there is no job opened in a specific month, the graph displays wrong results for that month.

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.