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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
ss8551
Helper II
Helper II

How to calculate the date diff to calculate the date diff based on a value of one column

I have a table that I need to deteremine if a rep took a course on a date (post-trained) otherwise (pre-trained)
so that I can compare performance.

When I do this in Power BI I can find the date, however the trained date only appears in one column and therefore I cannot find the differnce between the date and course completed date since other dates are blank.
When this occurs it only shows as Post training on the date that the training occurred and all others are Pre-training. I need to have PBI calculate the differnce between the date that the training of a particular course(s)
based on the course number and the actual date. So in the example above the trained date - date = 0 and should be pre-trained. But the following day, it should show a date difference of 1 and be Post-Trained.

a sample data is below.
if it matters most of the data that I'm sourcing from is based on a direct query
When I try to do a calculation to deteremine Pre or Post it only looks at the trained date column to calculate the difference and returns one row.


Timeframe = IF('Training'[Course]=580683944,DATEDIFF(FIRSTDATE('Date'[Date]),MAX('Training'[Trained Date]),DAY))
Timeframe_2 = if('Training Class'[Timeframe]<1,"Pre-training","Post-Training")

 

In the example below I would want to show Post-Training after 3/15/22 ane Pre-training on 3/15/22 and prior.

 

Any Help is appreciated.

 

Dateemployee_IDTimeframe_date_diffPre-Post_TrainedTrained DateCourseTrained Date
2/10/2022zy645 Pre-training 3569718952/10/2022
2/24/2022zy645 Pre-training 5859384232/24/2022
3/15/2022zy645 Post-Training3/15/20225806839443/15/2022
3/16/2022zy645 Pre-training 7966208493/16/2022
4/4/2022zy645 Pre-training 9111001024/4/2022
4/20/2022zy645 Pre-training 9455547224/20/2022
5/4/2022zy645 Pre-training 5460211255/4/2022
6/30/2022zy645 Pre-training 2584775076/30/2022
7/13/2022zy645 Pre-training 9325213987/13/2022
7/19/2022zy645 Pre-training 9921192937/19/2022
7/26/2022zy645 Pre-training 6712594557/26/2022
7/27/2022zy645 Pre-training 2001818877/27/2022
8/2/2022zy645 Pre-training 7532392928/2/2022
9/14/2022zy645 Pre-training 3241849009/14/2022
10/6/2022zy645 Pre-training 66589096010/6/2022
10/12/2022zy645 Pre-training 47771544510/12/2022
10/13/2022zy645 Pre-training 96932341710/13/2022
10/20/2022zy645 Pre-training 94334447710/20/2022
10/26/2022zy645 Pre-training 89021277610/26/2022
8 REPLIES 8
ss8551
Helper II
Helper II

Thanks, of course you're correect.  however, i've had dfifficulties calculating the datediff between the two columns since the trained date only populates on one row.  is there a way to calculate the date diff between the trained date and date (sort of locking in on the one cell for the value of the trained date) or populate all the empty cells for dates before and after the trained date with the same value of trained date?  then i would be able to calculate the datediff between the two columns.  otherwise any tips that you can give me on index would be appreciated.  the row is coming from a direct query (liked from another powerbi source) and not sure about inexing or if this can be done with a direct query at all.

 

thanks again for any assistance.

the row is coming from a direct query

Next time please mention this fact earlier.

 

you cannot implement column logic in Direct Query connections if the data does not come from the same row.

so you do not have any suggestions on a resolution to my isssue?  I did mention in my very first post that this was a direct query.  I stated this since I knew that this could be an issue.  Is there any way to either pull this data into antother tab and/or copy the data so that it fills all rows of the column?

You are right, I should have read your first post more attentively.  I do not think there is a  way to accomplish this in Power BI. This needs to be done at the data source.

so i am using a direct query but, i also have other tabs.   Is it possible to pull this data into another tab of Power BI that is not a Direct Query and then accomplish the same?  I'm trying to use the data from the Direct Query to add to some additional data in Power BI that I have created using a Snowflake Connecton.  If I add a coulumn into one of my tabs can I pull this data into one of these tabs and fill the empty cells either in this column or another column with this same date (so for example date of 1/1/22 to today to be filled with the date the training completed date)?  so that I'm not trying to add it to a Direct Query directly but from a column i pulled in from a Direct Query  to a new column in My Power BI.

 

Not sure if this works but looking for any way to get this to function.

 

Thanks againd for your assistance.

ss8551
Helper II
Helper II

in the fields above i would like to calculate the datediff between the trained date and the date and have a value filled into the column of Timeframe_date_diff.  ultiimately i need to use this field to determine if <1 they are pretrained and >1 trained.  When i've attempted to do this it only populates one value and one result only for the date that they were trained.  it will show post trained on that date and all others appear as pretrained before or after that dated (likely due to the trained date column being empty except for the date that they were trained on).  Not sure of how to resolve this and/or if it may be needed/possible to fill the empty cells above and/or below the trained date with the value of the date that they were trained on.

 

Thank you for any assistance you can provide.

Power BI has no concept of "above" or "below".  It is your responsibility to indicate how rows should be addressed/sorted (for example by adding an index column).

lbendlin
Super User
Super User

Please indicate what you mean by "difference" - where would that show as a result based on your sample data?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.