Replace the text of a specific cell given certain circumstances - replace

I am creating a work schedule for the company I work at. There are four different jobs at the company and therefore 4 separate tabs for schedules.
I have a tab specifically for when an employee calls out sick or requests time off. I am looking for a way for when the user enters the employee's name, specific date, and sick/request off, for it to automatically update the work schedule that that employee belongs too (Job1, Job2, Job3, or Job4)
Example:
This is John Doe's Work Schedule for Job 1(and therefore located on Job1 tab)
John Doe calls out sick on Friday, 01/18/19. The supervisor fills out the following on Time Off Reqs/Sick tab
Given that the user inputs the above data in Time Off Reqs/Sick tab, I would like John Doe's Schedule to change automatically in Job1 tab to the following
John Doe
Here is the link to my dummy data
Any help is greatly appreciated!

I was able to get what you were looking for. See the sheet (and make a copy to modify) HERE.
I used the formula below in each cell of the "Job1" sheet (for this example, I only did it for Column F).
=IFERROR(IF(AND(D2<>"SATURDAY",D2<>"SUNDAY",ISNA(QUERY(Requests!A$2:C,"Select C where A='"&$F$1&"' and B = date '"&TEXT(DATEVALUE(C2),"yyyy-mm-dd")&"'",0)))=TRUE,"Work",QUERY(Requests!A$2:C,"Select C where A='"&$F$1&"' and B = date '"&TEXT(DATEVALUE(C2),"yyyy-mm-dd")&"'",0)),"Off")
You could probably also use multiple INDEX/MATCH statements to get what you're looking for. If you restructure the data, you may be able to use ARRAYFORMULA to reduce the number of formulas you need to use.

Related

Count occurances in multiple filtered rows

I need a little help since im new to PowerBI. I have a data set which says what have been eaten in a specific day. At the end there are columns which show if the day before the overall feeling was better (so in this specific day it got worse). I got up to 30 Ingredients and 5 days before. The "1" in e.g. Day2 means its TRUE for condition "2 days before it got worse"
The data looks like this:
Data set example
Now, I want to retrieve and add up all ingredients, which has been eaten at "Day1", "Day2" and so on, so I can see which food is maybe causing problems because it should appear more often in the days before or at least appear in every case there. How do I achieve this?
For example I can see then, that on Day2 overy often Ingredient "Apple" appears, so there could be an assumption that Chicken meat is not good for this person.
I tried to pivot the table, as well as disconnect the "DayX" into another table and make relationship between them, but nothing adds up the things in the way I want it to.

Google Sheets, multi-tab, multi-criteria if statements

I'm building a staff allocation sheet for our production teams so that management can see (graphically) the peaks and troughs for each department. I've anonymised the data and shared it here: https://docs.google.com/spreadsheets/d/140w_v_ApksXH2q7h_dK5Iglm0VOTF1Zk9fq9jPxF5BM/edit?usp=sharing
What I am attempting to achieve is to have the week commencing dates across the top, the employees down the left (Based on a unique list of employees form the department tabs) and the individual cells populated with the relevant show number (I've manually entered the first two employees).
I had done this successfully by having hidden proxy columns for each show that pull a start and end date from the department sheet via and indirect lookup. Where this falls down is if an employee works on a production at two separate times, e.g. all of May and all of August but not between those months.
I initially attempted a series of nested ifs:
=if(and(indirect($A3&"!$B:$B")=$B:$B,
indirect($A3&"!$E:$E")<=AK$2,
indirect($A3&"!$F:$F")>AK$2,
indirect($A3&"!$C:$C")="SHOW #1"
),1,
if(and(indirect($A3&"!$B:$B")=$B:$B,
indirect($A3&"!$E:$E")<=AK$2,
indirect($A3&"!$F:$F")>AK$2,
indirect($A3&"!$C:$C")="SHOW #2"
),2,
if(and(indirect($A3&"!$B:$B")=$B:$B,
indirect($A3&"!$E:$E")<=AK$2,
indirect($A3&"!$F:$F")>AK$2,
indirect($A3&"!$C:$C")="SHOW #3"
),3,
. . .
if(and(indirect($A3&"!$B:$B")=$B:$B,
indirect($A3&"!$E:$E")<=AK$2,
indirect($A3&"!$F:$F")>AK$2,
indirect($A3&"!$C:$C")="SHOW #17"
),17,
0)))))))))))))))))
Hoping that this would calculate in each cell and return the correct result, however this did not work, that's when I discovered if() doesn't work with ranges in this context! I've effectively hit a wall on this.
I feel like I'm missing something obvious in this and would appreciate any help!!!

dax code for count and distinct count measures (or calculated columns)

I hope somebody can help me with some hints for the following analysis. The students may do some actions for some courses (enroll, join, grant,...) and also the reverse - to cancel the latest action.
The first metric is to count all the action occurred in the system between two dates - these are exposed like a filter/slicer.
Some sample data :
person-id,person-name,course-name,event,event-rank,startDT,stopDT
11, John, CS101, enrol,1,2000-01-01,2000-03-31
11, John, CS101, grant,2,2000-04-01,2000-04-30
11, John, CS101, cancel,3,2000-04-01,2000-04-30
11, John, PHIL, enrol, 1, 2000-02-01,2000-03-31
11, John, PHIL, grant, 2, 2000-04-01,2000-04-30
The data set (ds) is above and I have added the following code for the count metric:
evaluate
sumx(
addcolumns( ds
,"z+", if([event] <> "cancel",1,0)
,"z-", if([event] = "cancel",-1,0)
)
,[z+] + [z-])
}
The metric should display : 3 subscriptions (John-CS101 = 1 , John-PHIL=2).
There are some other rules but I don't know how to add them to the DAX code, the cancel date is the same as the above action (non-cancel) and the rank of the cancel-action = the non-cancel-action + 1.
Also there is a need for adding the number for distinct student and course, the composite key . How to add this to the code, please ? (via summarize, rankx)
Regards,
Q
This isn't technically an answer, but more of a recommendation.
It sounds like your challenge is that you have actions that may then be cancelled. There is specific logic that determines whether an action is cancelled or not (i.e. the cancellation has to be the immediate next row and the dates must match).
What I would recommend, which doesn't answer your specific question, is to adjust your data model rather than put the cancellation logic in DAX.
For example, if you could add a column to your data model that flags a row as subsequently cancelled, then all DAX has to do is check that flag to know if an action is cancelled or not. A CALCULATE statement. You don't have to have lots of logic to determine whether the event was cancelled. You entirely eliminate the need for SUMX, which can be slow when working with a lot of rows since it works row by row.
The logic for whether an action is cancelled or not moves to your source system (e.g. SQL or even a calculated column in Excel), or to your ETL (e.g. the Query Editor in Power BI) which are better equipped for such tasks. The logic is applied 1 time and then exists in your data model for all measures, instead of needing to apply the logic each time a measure is used.
I know this doesn't help you solve your logic question, but the reason I make this recommendation is that DAX is fundamentally a giant calculator. It adds things up. It's great at filters (adding some things up but not others), but it works best when everything is reduced to columns that it can sum or count. Once you go beyond that (e.g. wanting to look at the row below to adjust something about the current row), your DAX is going to get very complicated (and slow), whereas a source system or the Query Editor will likely be able to handle such requirements more easily.

How to specify the currency for GoogleFinance historical data

I'm having a problem using Google Finance historical data. I need to know the price a particular stock had on a particular date (Usually within the last month).
The problem is, when I use a URL such as https://finance.google.com/finance/historical?q=abx I get different results depending on where I issue the query from.
At home I'm in Argentina and my production server is in the US... when I run the query locally I get the prices in AR$, but when run from the server I get USD (Which is what I actually need).
I tried using a X-Forwared-For header but didn't make a difference...
Ideally I'd like to send an extra parameter (something like cur=USD) to explicitly ask for USD... is there such a thing?
Thanks
I use, currency conversion along with the price of the stock.
For Example:
Price of ABB Ltd in SEK = GOOGLEFINANCE("ABB","price") * GOOGLEFINANCE(("CURRENCY:USDSEK"))
Then I format the cells, rows, columns with prices to local currency(i.e. SEK) as mentioned in the link: Format Numbers in excel.
You could add other parameters such as date as mentioned in below link:
Get exchange rate on a specific date from GoogleFinance

Automating Chart Data generation for a Daily Expenses per Tag

Using Google Spreadsheets. Here's an attempt to replicate my table needs:
2012-08-30 food $15 expensive dinner
2012-08-30 food $10 pizza!
2012-08-30 other $30 that damn painting
2012-09-02 home $40 can't remember
2012-09-02 other $5 toilet paper
2012-09-02 home $2 buying new flowers
I can already do 2 things with it, but it is so far from optimal it becomes negligible.
First, Using SUMIF:
food $25 <- SUMIF(B:B;"food";C:C)
other $35
home $42
Then, combining it with ARRAYFORMULA:
food home other
2012-08-30 $25 $0 $30 <- ARRAYFORMULA(SUMIF(A:A&B:B;2012-08-30&"food";C:C))
2012-09-02 $0 $42 $5
See where this can become too big? Well...
I want to do 2 graphic charts out of this. Of course, the main one is the second:
A pie, from the first example. On using the SUMIF, I need to explicitly, write "food" there (or reference, whatever). Could that be done automagically filling every tag found?
While I can live without this, it may be the answer to the second, main question;
A plot or timeline, from the arrayformula. It should trace each tag in a plot along the time.
Is it even possible to be done? If not, any suggestions? I'm keen to start scripting if needed (and worth it). Or move away from google. Or from spreadsheets all together (lastly). Python maybe? Ruby?
Or maybe I'll just leave it as it is, if it's tooooo much trouble.
Using QUERY, you can generate the first table (with headers) using:
=QUERY(B:C;"select B, sum(C) where B != '' group by B label B 'Category', sum(C) 'Total'";0)
and this should be fairly easily plotted as a pie chart. You can select a range for the chart that is much longer than the current table to accommodate growing data, and the pie chart will conveniently ignore blank rows.
The second table can be generated using:
=QUERY(A:C;"select A, sum(C) where A is not null group by A pivot B";0)
and you can experiment with various chart types to achieve the desired visualisation.
edit
To provide a table that populates with zeros instead of blanks as per your comment; assuming the upper left (blank) cell of the table is I1, then in I2:
=SORT(UNIQUE(A:A))
and in J1:
=TRANSPOSE(SORT(UNIQUE(B:B)))
and then in J2:
=ArrayFormula(IF(I2:I*LEN(J1:1);MMULT(I2:I=TRANSPOSE(A:A);(J1:1=B:B)*C:C);IFERROR(1/0)))
Note this will populate CONTINUE functions to the far bottom and far right of the spreadsheet, over-writing everything in their path. So probably best to have a sheet dedicated to this table.
In general, Spreadsheets are not Databases, and this is a task for which you are fast approaching needing a database. However, as luck would have it (depending on how you look at it, anyhow), Google Spreadsheets actually do have some database-like access APIs, so you can probably do what you want:
http://googleajaxsearchapi.blogspot.com/2008/03/introducing-latest-ajax-api-google.html
https://developers.google.com/chart/interactive/docs/querylanguage
http://blog.ouseful.info/2009/05/18/using-google-spreadsheets-as-a-databace-with-the-google-visualisation-api-query-language/