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

Need help creating calculated column using data from different table between 2 dates

Hello Again,

 

I have a table titled "Daily Amperage Data" and I have a table titled "Current Efficiency". I would like to add a new column within "Current Efficiency" which will generate an average amperage for the time between when a cell is harvested. I would also like to add another column which would have the value of the number of days that have elapsed since that cell was harvested.

 

Here are my Tables:

Daily Amperage Data

Production DateNorth AmpsWest Amps
Friday, January 1, 20102360521511
Saturday, January 2, 20102339720766
Sunday, January 3, 20102086224511
Monday, January 4, 20102486423175
Tuesday, January 5, 20102253320375
Wednesday, January 6, 20102355223112
Thursday, January 7, 20102029920081
Friday, January 8, 20102234520276
Saturday, January 9, 20102366923203
Sunday, January 10, 20102464722383
Monday, January 11, 20102040521362
Tuesday, January 12, 20102294521624
Wednesday, January 13, 20102044322062
Thursday, January 14, 20102443924136
Friday, January 15, 20102038221179
Saturday, January 16, 20102045622797
Sunday, January 17, 20102003224161

 

Current Efficiency 

Production DateCell NumberProductionTrue Production
Friday, January 1, 20101501251312713
Friday, January 1, 20101601014810348
Friday, January 1, 20101701078810988
Friday, January 1, 20102501015510355
Friday, January 1, 20102601280413004
Friday, January 1, 20102701124211442
Saturday, January 2, 20101801161411814
Saturday, January 2, 20101901058610786
Saturday, January 2, 20101001239912599
Saturday, January 2, 20102801220012400
Saturday, January 2, 20102901137511575
Saturday, January 2, 20102001079910999
Sunday, January 3, 20101101141311613
Sunday, January 3, 20101201236712567
Sunday, January 3, 20101301110911309
Sunday, January 3, 20102101181012010
Sunday, January 3, 20102201194112141
Sunday, January 3, 20102301169011890
Monday, January 4, 20101401188012080
Monday, January 4, 20101501220112401
Monday, January 4, 20101601242412624
Monday, January 4, 20101701034210542
Monday, January 4, 20102501159711797
Monday, January 4, 20102601181212012
Tuesday, January 5, 20102701142911629
Tuesday, January 5, 20101801186112061
Tuesday, January 5, 20101901187112071
Tuesday, January 5, 20101001242212622
Tuesday, January 5, 20102801037610576
Tuesday, January 5, 20102901272812928
Wednesday, January 6, 20102001288113081
Wednesday, January 6, 20101101042110621
Wednesday, January 6, 20101201081311013
Wednesday, January 6, 20101301188612086
Wednesday, January 6, 20102101132411524
Wednesday, January 6, 20102201167011870
Thursday, January 7, 20102301165211852
Thursday, January 7, 20101401110711307
Thursday, January 7, 20101501174511945
Thursday, January 7, 20102301076110961
Thursday, January 7, 20102401051410714
Thursday, January 7, 20102501006810268
Friday, January 8, 20101601122511425
Friday, January 8, 20101701027610476
Friday, January 8, 20101801088511085
Friday, January 8, 20102601172611926
Friday, January 8, 20102701241712617
Friday, January 8, 20102801196912169

 

So I'd like to create a new column which shows the average Amperage for cell 150 over its cycle. So initially it is harvested on January 1st. And it is harvested again on January 5th. I would like the column to be the average of amps between January 1st and January 5th. The second column should be something along the lines of Days between when that cell was harvested. 

 

Cells fed by the North Amperage are the "100" cells. 110, 120, 130 etc.

Cells fed by the West Amperage are the "200" cells. 210, 220, 230 etc.

 

Please let me know if you need further clarification. I understand I'll have null data in the first few days until the cycle repeats itself.

 

Thank You for your help!

7 REPLIES 7
V-pazhen-msft
Community Support
Community Support

@jaymetbar 

Did you missed out a column somewhere that should show us NorthAmps/West Amps for each cell?

 

Regards

Paul

Hi Paul,

 

Sorry, i got a little hasty when making my dummy data and left out some key info. Cells that are 100-190 are fed by North Amps and cells that are 200-290 are West Amps.

@jaymetbar 

1. I assumed you related the two tables with Dates, you can move the Amps to the Current Efficiency table using, I used SWTICH instead of IF because there are may be 300, 400... cells.

 

Amps = SWITCH(TRUE(),
[Cell Number]>=100 && [Cell Number]<=190,RELATED('Daily Amperage Data'[North Amps]),
[Cell Number]>=200 && [Cell Number]<=290,RELATED('Daily Amperage Data'[West Amps]))

 

 2. Create the two expected columns with: 

 

Column 1 = 
CALCULATE(AVERAGE('Current Efficiency'[Amps]),FILTER('Current Efficiency',[Cell Number]=EARLIER([Cell Number])&&[Production Date]<=EARLIER([Production Date])))

Column 2 = 
var nextdate = CALCULATE(MAX([Production Date]),FILTER('Current Efficiency',[Cell Number]=EARLIER([Cell Number])&&[Production Date]<EARLIER([Production Date])))
Return DATEDIFF(nextdate,[Production Date],DAY)

 

 

Pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/paul_qiuyunus_onmicrosoft_com/ERRN_hTYt3FNoMlzT7tm...

 

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

Or we could eliminate the need for the plating days and use a sum function to sum the amps daily between those two harvest dates. That might make it an easier calculation. I'll try that in the mean time and study more up on Earlier, Filter, expressions.

 

 

Hi Paul!

 

Sorry I've been swamped in other projects and am barely circling back to this one.

So I inputted your code and it is calculating. The Plating Days calculation works fine ("Column 2" Thanks for that!)

 

So let me give some more detail:

We have cells that are plating every day and are fed amperages which fluctuate daily. The daily average amps is captured in the Daily Amps Table. I think the logic of sorting amps works for the "Amps" column you created. However i think the value itself is unnecessary.

 

I think what we want to do is have logic which looks at if a cell is in the west and the north, then it needs to take the average amperage from the "Daily Amperage Data" table between the dates it was harvested and when it was harvested last. 

 

I think it was trying to do it within the current efficiency table and getting a lower value.

 

So for cell 150 it was initially harvested on Jan 1 2010 and then it begins plating again on that date until it is harvested again on Jan 4 2010.

 

The Daily Amps for the North during that range were 23605, 23397, 20862, and 24864 respectively so the average amps for cell 150 over the cycle should be 23,182.

 

Does that make sense? I really appreciate your help and taking the time to look into this.

Greg_Deckler
Super User
Super User

So what tells us Cell 50 is in North amps?

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

Sorry about that. I corrected the data to include more cells. Anything in the 100 series would be a North Amperage fed cell and anything in a 200 series would be a West Amperage fed cell.

 

 

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.