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
JpTall
Frequent Visitor

Creating a calculated collumn with the use of filters

I am trying to create a calculated column that captures the first appointment date that is an ‘install’ and is NOT cancelled.

 

I tried this formula:

First install date = CALCULATE(FIRSTDATE(APPOINTMENT[Appt_Date]),FILTER(APPOINTMENT,APPOINTMENT[App_Type_Code]="IN" && (APPOINTMENT[Cancelled]=BLANK()||APPOINTMENT[Cancelled]="N")))

IN = install

N= no

But I get the same date for each record in the entire column.

 

When I don’t use the filters and instead use this formula:

First appointment date = CALCULATE(FIRSTDATE(APPOINTMENT[Appt_Date])

 

However, it does a good job of getting the first appointment date for each record.

 

Is it possible to use a calculated column with filters to accurately get the first install date into my table? The formula with filters works with a measure but I need the column for my visuals and other calculations.

 

Thanks in advance for any help.

1 ACCEPTED SOLUTION
JpTall
Frequent Visitor

It is confidential data, so I can't share too much.

 

There are two tables:

1. Unique values for appointment reference (APPOINTMENTS)

2. Unique values for referral reference (REFERRALS)

Tables joined using the referral reference (*:1, single filter)

 

I think I have got a work around, using the thinking in your reply @fhill 

 

In the appointment table, I calculated a column to produce the date only when it's an install NOT cancelled:

Install date = IF(APPOINTMENT[App_Type_Code]<>"IN",BLANK(),IF(APPOINTMENT[Cancelled]="Y",BLANK(),APPOINTMENT[Appt_Date])).
 
Then in the Referrals table, I calculated a column to get the first install date:
First install date column = CALCULATE(FIRSTDATE(APPOINTMENT[Install date]))
 
This then creates a column that is accurate for each record in the table.

View solution in original post

6 REPLIES 6
JpTall
Frequent Visitor

Just a bit more information for what I'm trying to achieve.

The data:

Referral no.Client no.Appointment no.Appt dateApp_Type_CodeCancelled
000001001000108/01/2019AXY
000001001000221/01/2019AX 
000001001000302/02/2019IN 
000002002000415/01/2019AXN
000003003000515/01/2019AX 
000003003000628/01/2019RE 
000003003000705/02/2019INY
000003003000807/02/2019INN
000003003000915/02/2019IN 
000004002001021/01/2019AX 
000004002001128/01/2019IN 

 

The end goal:

Referral no.Client no.Appointment no.First Install Date
000001001000302/02/2019
0000020020004 
000003003000807/02/2019
000004002001128/01/2019
fhill
Resident Rockstar
Resident Rockstar

*** These DAX values assume you only have 1 Date per Apt No line...  ***  and please excuse our reversed dates here in the states...

 

First Install Date = IF (CALCULATE( FIRSTDATE( Table1[Appt date]),  -- IF Statement to check for lines without an "IN" or "N" or "" or " " in Cancelled.  This is needed to produce a BLANK LINE with a DAX measure for any row NOT finding a match.
         FILTER(Table1, Table1[App_Type_Code] = "IN" && Table1[Cancelled] <> "Y")) = BLANK(), " "  -- Here's the Blank Line i'm using to 'fill' the blank row because DAX Measure typically exclude Blank results...
         , CALCULATE( FIRSTDATE( Table1[Appt date]), FILTER(Table1, Table1[App_Type_Code] = "IN" && Table1[Cancelled] <> "Y")))
 
Apt_No = IF (CALCULATE(FIRSTDATE( Table1[Appt date]), FILTER(Table1, Table1[App_Type_Code] = "IN" && Table1[Cancelled] <> "Y")) = BLANK(), MAX(Table1[Appointment no.]),  -- Check for No Good Installs, and use MAX Apt # instead as shown in your example...
CALCULATE(MAX(Table1[Appointment no.]), FILTER(Table1, Table1[App_Type_Code] = "IN" && Table1[Cancelled] <> "Y" && Table1[Appt date] = CALCULATE(FIRSTDATE( Table1[Appt date]), FILTER(Table1, Table1[App_Type_Code] = "IN" && Table1[Cancelled] <> "Y")))))   -- Else Find Apt # matching the First Install Date
 

Capture.PNG

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




JpTall
Frequent Visitor

@fhill  Thank you for your response!

 

Did you use a measure or a calculated column? I still can't get this to work when I create a calculated column. And I have just noticed the value that is being produced for each record is incorrect (i.e. not an install). It is just the First Appt in the table, or MAX Appt no in the table. 

 

I have a table with unique references for the Referral number and was hoping to create the column in this table.

 

Is this logic only successful when used in a measure?

fhill
Resident Rockstar
Resident Rockstar

Both my examples were measures. Please post your exact table structures, and raw sample data from each table, so I can replicate your data source.



Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




JpTall
Frequent Visitor

It is confidential data, so I can't share too much.

 

There are two tables:

1. Unique values for appointment reference (APPOINTMENTS)

2. Unique values for referral reference (REFERRALS)

Tables joined using the referral reference (*:1, single filter)

 

I think I have got a work around, using the thinking in your reply @fhill 

 

In the appointment table, I calculated a column to produce the date only when it's an install NOT cancelled:

Install date = IF(APPOINTMENT[App_Type_Code]<>"IN",BLANK(),IF(APPOINTMENT[Cancelled]="Y",BLANK(),APPOINTMENT[Appt_Date])).
 
Then in the Referrals table, I calculated a column to get the first install date:
First install date column = CALCULATE(FIRSTDATE(APPOINTMENT[Install date]))
 
This then creates a column that is accurate for each record in the table.
fhill
Resident Rockstar
Resident Rockstar

Glad you got it working.  If you are good, please mark resolved.

 

FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




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.