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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Calculated column based on filters.

I want to create the following measure:

 

Hires = count of those employees whose transaon date = date[first date]). When I manually enter the first date, the value comes up. Employee count 1.PNG

 

The Manual part is the date column. However, when I give it as follows: Employee count 2.PNG I get an error that CALCULATE has been used in a TRUE/FALSE expression which is wrong, so I tried the one as below

 

Employee count 3.PNG

 

But this just show a blank value for me even when I apply filters. However, for manually entering the date it comes up. Basically I would like to calculate the count of employees, if the filter the criteria that Employees[transaction_date)=Date(First_date). The first date has been created in a new table by me and works perfectly when filters are applied and changes accordingle. However, when I apply the same filter to the calculation, it does not work.

 

Any suggestions? Thank You!

17 REPLIES 17
Anonymous
Not applicable

@Anonymous try adding the first date calculation in the hires table. 

 

Is the transaction date hooked to the date table? 

what is the calculation for the first date?

Is first date driven by a filter?

Anonymous
Not applicable

My first table is Employees:

 

ID      Transaction Date

1        7/31/2018

2        7/31/2018     

3        7/31/2018

4        12/31/2017

5        12/31/2017

6        12/31/2017

7         12/31/2016

8          12/31/2016

9         12/31/2016

 

And a Date Table:

 

Date                                                                     Year

(Ranges from 1/1/2010 to 12/31/2020)              (The corresponding year)

 

I have added to measures in the Date Column as : First Date = FIRSTDATE('Date Table'[Date])-1

 

                                        Last Date = IF(YEAR(LASTDATE('Date Table'[Date]))=YEAR(TODAY()), LASTDATE(Sheet1[TRANSACTION_DATE]), LASTDATE('Date Table'[Date]))

 

So the First date is actually 12/31/year of whatever year is chosen. Ex if year filter is 2013, first date should show 12/31/2012 and

last date is December of that year.

However, if my year is 2018, then last date needs to the last date of July that is 7/31/2018. And similarly next month, it would automaticlly change tp 8/31/2018.

Date 1.PNG

Date 2.PNG

The date table and empoyees table are linked by transaction date in the employee table and date in the date table. The filter used is the year column.

I need to calculate Hiring Rate as HR = count of hires/((COunt of employees on 12/31/2016 + count of employees on 12/31/2017))/2 if the year chosen is 2017.

Similarly, HR in 2018 eould be count of hires/((Count if employees on 12/31/2017 + Count of employees on 7/31/2017))/2 if year is 2018. The 7/31/2018 in denominator would automatically change to 8/31/2018 in August.

 

This is what i am trying to do and the denominator part is confusing me.

 

For the first part of denominaot, I gave HR1 = CALCULATE(COUNT(Employees[ID), FILTER(Employees, Employees[TRANSACTION_DATE]=Date Table[First DAte])) -> Syntax was correct.

Seconf part of denominaotr, I gave HR2 = CALCULATE(COUNT(Employees[ID]), FILTER(Employees, Employees[TRANSACTION_DATE]='Date Table'[Last Date])).

 

So the filters need to apply accordingly and work, is what i thought.

 

I hope i was able to explain the situation appropriately!

 

Anonymous
Not applicable

Hey, how do I post the Power BI File?

Anonymous
Not applicable

Post it to dropbox or google drive and send a link here.

Anonymous
Not applicable
Anonymous
Not applicable

@Anonymous Here are somethings I found. If you plug transaction date, date and first date in one table you will realize that first date dynamically changes based on what you prop in to 1 day prior to dec 31, 2016. 

 

To fix this I removed -1 from first date formula 

 

Also

1) first date & Last date need to be calculated columns. 

2) I created a new related column in sheet1 related(date[first date])

 

Also all the dates need to be in same format either datetime or date.

Anonymous
Not applicable

@Anonymouswere you able to calculate the denominator accordinglt? If yes, can u share the file with me?

Anonymous
Not applicable

@Anonymous if you apply the same changes I made to firstdate to last date it should work properly. the formula is the same just the fields are different.

Anonymous
Not applicable

okay i'll try and let u know in a while! Thanks @Anonymous@

Anonymous
Not applicable

@Anonymous was my solution the accepted solution???

Anonymous
Not applicable

@Anonymous Hey, Sorry. I just tried it and it dint work. However, I have usd tweaking to make it work now.

Hi @Anonymous,

 

Could you please share the solution and mark it as a solution?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hey I have the following situation.

 

I have given a date range from 2010 to 2020.

 

I want to create the following measure: Count the number of employees if date hired of employees = last date in date table (I created this date table), else 0.

 

I created the following measure till now:  Measure = CALCULATE(COUNT(Employees[ID]), Filter(Employees, Employees[HireDate]= 'Date Table'[Last Date])

 

So bascally I want to calculate the count when hire date matches last date, else I want it to return 0. However, it returns weird values even for the year 2019 in the filter. Is there a way in which this can be calculated?

 

Thank You!

@Anonymous,

What is the last date in date table? Is it a measure? Could you please share sample data of your table and post expected result  based on the sample data?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hey, I had posted my sample under a different discussion called "Calculated Column based on Filters" yesterday. There is a detailed description there. @v-yuezhe-msft

@Anonymous,

Do you want to get same expected result in the two different discussion? If so, I will merge the  two threads.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-yuezhe-msft Yes, They are related. So I guess you can merge it. Thank You!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors