Get the last 5 results of column C or D if column A or B is equal to ___? - if-statement

I know the title is a horrible description, sorry.
Basically I have a sheet with results from basketball games. So in column A I have the home team. In column B I have the away team. In column C the home team's points. In column D the away team's points. There's about 500 rows worth of data at the minute.
What I want to do is the following:
Say I want to get the average points scored by the New York Knicks in their last 5 games. The most recent games are at the bottom of the sheet, and the first/oldest ones at the top of the sheet.
So across the bottom/last 5 instances of "New York Knicks" in column A and B, I want the average of the results of C (if New York Knicks is in column A) and D (if in column B).
I know how to do this if I would want just the last 5 home games for instance (so in that instance I basically query the bottom 5 results of column C in the last 5 occurrences of column A being New York Knicks). I don't know how to do it when I am looking for when New York Knicks occurs in either column A or B, and then have to get the averages from column C or D.
Can anyone help?

this will transform your 4 columns into 2 columns:
=ARRAYFORMULA(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A2:B<>"", "♠"&A2:B&"♦"&C2:D, )),,999^99)),,999^99), "♠")), "♦"))
and average score of the last 5 games:
=ARRAYFORMULA(AVERAGE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A2:B<>"", "♠"&A2:B&"♦"&C2:D, )),,999^99)),,999^99), "♠")), "♦"),
"select Col2
where lower(Col1) contains 'new york knicks'
offset "&COUNTIF(A2:B, "new york knicks")-5)))

Related

Remove single column value from row total value a a PowerBi Matrix

I have a matrix that has numerous categories/columns with a total of each row. I want a specific column to remain in the matrix, but should not form part of the row total.
Dog
Cat
Chicken
Total (Excl. Chicken)
2
2
10
4
2
4
100
6
I only find ways to either remove the row total of the column totals for specific columns. Also appear that measures does not work in matrix's. Do I need to rather use a table with a added measure or is there a way with a matrix?

Power BI substruct from salary for each person and month

My Table
Hi ,
I have this table in power bi . Each person has lines for each month passes . 5 months equals to 5 appearances in the list. for each line and the number of days ( between START AND END column) i want to substract from the MONEY column the MONEY PER MONTH COLUMN and keep the differnce .After this differnce to be substracted again with the column MONEY PER MONTH from this row until i have 0 . The only catch is that i want if the difference( happens a lot of times at month 5 out of 5 ) if the MONEY PER MONTH column is less than 20 , i want it to be 20 and the before result 240. After the last month when a new name record comes the money again to be 1040
BASICALLY I WANT TO FORM THE RED LINED COLUMN IN IMAGE BELOW COLUMN THAT I WANT TO ADD

Create a monthly graph containing dynamical values

I discovered PowerBI few hours ago and I am trying to render a new graph, pretty complex from my data.
My subject:
I have a list of employees from my society with some information (name, location, seniority, ....) inside a table named Suivis de mission.
I'm focusing on seniority column. I have to display, monthly, the number of employees which has less than 3 seniority years, more than 3, more than 5 and more than 8.
This field is calculed through another field (date_de_changement_de_mission) by the next formula:
(today - date_de_changement_de_mission) / 365
It gives me a number according to the seniority years (above in french)
My experimental work:
I tried to make some things and this is what I have up to now.
I created a new table with months (string column1 and int column2) and the third column according to the number of employee with less than 3 seniority years for each month.
This is the formula that I'm trying to implement in order to get the number but I have lot of mistakes :
Nbr_inf_3_ans = SUMX('Suivis de mission';
IF(
'Suivis de mission'[Activité] = "En poste";1 &&
DIVIDE(
DATEDIFF(01/01/2019;'Suivis de mission'[Date de changement de mission].[Date];DAY);365)
;"null"))
The formula must contains several conditions :
Field 'Suivis de mission'[Activité] has to be : "En poste"
Loop over each month in my table (if the month is not targed, display 0)
I'm a bit lost.
Assuming that:
You want to do it in Power Query Editor
You already created the "seniority" and "month" ("mois*") columns
You are not worried about the year (you are really grouping just by month)
Then these steps may help you to begin:
Create a custom column name "IsLesserThan3" with the formula:
if [Seniority] < 3 and [Activité] = "En poste" than 1 else 0
Change the formula to include the requirement about "if the month is not targed" (i didn't get what it means, sorry).
Choose "Transform" (menu), then "Group By", then basic, set group by = month, give it a name ("Nbr_inf_3_ans"), set operation = sum, set column = IsLesserThan3
EDITED
New extra assumption:
There is a second table with month description and month number and you want to create the new column there ("Nbr_inf_3_ans") and fill it, probably to grant all the months are there (including those with no occurrences).
With this new assumption in mind, the approach will be to join the two tables and do the same thing:
Create a custom column named "IsLesserThan3" with the formula:
if [Seniority] < 3 and [Activité] = "En poste" than 1 else 0
Change the formula to include the requirement about "if the month is not targed" (i didn't get what it means, sorry).
Change the type of the new column to integer (click the icon to the left of the column name).
Create a custom column named "Mois_int" with the formula:
Date.Month([date_de_changement_de_mission])
Then join the tables by month. To do that, select the other table and choose "Transform" (menu), then "Merge", then let the second table selected and select the first table as the "bottom" table, select columns "Mois_int" in both tables, set "join kind" = "left outer".
PowerBI will create a new column wich name is the name of the first table. Click the arrows icon in that column header and choose "aggregate" and mark only "sum of LesserThan3".

Create Calculated Column Based on Teams with Four Wins in Final Round Utilizing DAX

I need a calculated column for champions and runner up. To become a champion, a team must attain 4 wins in a given year in the final round. I just don't know how to translate that for DAX. I want to be able to have a Year Slicer that will show the Champion and Runner Up for a given year in a card.
I have tried a summary table and using TOPN, but since the count of finalists are all one, I am getting no luck. In the picture below, I would like a column delegating if a team is a champion or runner up
Create a new column by clicking in the Modeling tab and selecting 'New Column". Using the code below I created a new column which takes the column which contains the 'Count of Champions' and IF the number is greater than or equal to 4 then "Champion" is placed in the adjacent column, if the number is below 4, then "Runner Up" is placed in the adjacent column.
Status = IF(Table1[Count of Champions] >= 4, "Champion", "Runner Up")

Using ArrayFormula for a running total causes a circular reference

See attached Google Sheet for example/sample of my issue. I am trying to use an ARRAYFORMULA() to keep a running total in column C, based on adding the previous row's value in column C with the current row's value in column B. Before I make it an ARRAYFORMULA, it works fine. In column F-H, you can see I tried the array version and get a "circular dependency" error.
The working formula:
=B3+C2 (this is in cell C3)
The non-working formula (with the desired ARRAYFORMULA):
=ArrayFormula(G3:G+H2:H) (this is in cell H3)
My question is, what adjustments can I make to my formula that will allow me to auto-fill this formula down the page as new rows are added (and not populating data for blanks).
Name Days Total Days
Jane 5 6
Tom 2 8
Billy 4 12
Sue 6 18
Sally 1 19
Sample document
=ARRAYFORMULA(IF(B2:B="", ,SUMIF(ROW(B2:B), "<="&ROW(B2:B), B2:B)+1))
demo spreadsheet
if this is what you need ( to always sum total in C column ),
then you don't need arrayformula you can use this simple cell formula (this is C2 formula):
=B2+(If(ISNUMBER(C1), C1, 0))
and spread it down the page, here is the sheet I captured
cheers, kres