Google Spreadsheet multiple column filter condition grouping syntax - google-docs

This question is somewhat similar to
Google Spreadsheet multiple column filter using OR
but where as he asks for the equivalent of:
select count(*)
from Table
where A is not null and (B is not null or C is not null)
I would like to do:
select count(*)
from Table
where A is not null OR (B is not null AND C is not null)
In fact what I am trying to do is filter on a date and I have been using
=FILTER(YEAR(Hours!A2:A)=2012,MONTH(Hours!A2:A)>=8)
to give me August going forward.
but now I need to add a limit to a certain day for the month. I would need something like this:
=FILTER(MONTH(Hours!A2:A)=8, ( MONTH(Hours!A2:A)=9 AND DAY(Hours!A2:A)<=13) )
in order to have all of August and then September only up to the 13th.
Is there a Syntax that allows this?

to have all of August and then September only up to the 13th.
One way (and this would be a "general" solution for filtering between two dates):
=COUNT(FILTER(Hours!A2:A;Hours!A2:A>=DATE(2012;8;1);Hours!A2:A<=DATE(2012;9;13)))

Related

Power Query Data from different columns

i am new to Power query and i would like to learn a bit more about it. I am facing the following problem. My table looks like this (empty fields already removed):
What i'm trying is to get a new table where "Spalte2" holds my list of ISINs and S^"Spalte 8" but also "Spalte 9" and "Spalte 10" hold my portfolio share (komma separated).
EDIT: For clarification I hope to get something like this:
EDIT: I try to get a table in here, hope it works:
Spalte1
Spalte2
Spalte8
Spalte9
Spalte10
Bâloise Holding AG
CH0012410517
1,04
Null
Null
Barry Callebaut AG
CH0009002962
0,63
Null
Null
Galenica AG
CH0360674466
0,58
Null
Null
Givaudan SA
CH0010645932
1,24
Null
Null
HelloFresh SE
DE000A161408
527.705,26
1,85
Null
Kering S.A.
FR0000121485
431.145,00
1,51
Null
Standard Chartered PLC
GB0004082847
4,610 117.699,50
Null
0,41
Unilever PLC
GB00B10RZP78
42,305 315.241,76
Null
1,11
What i'm trying to get is this:
Spalte2
Spalte8
CH0012410517
1,04
CH0009002962
0,63
CH0360674466
0,58
CH0010645932
1,24
DE000A161408
1,85
FR0000121485
1,51
GB0004082847
0,41
GB00B10RZP78
1,11
Which way can i use in PQ to match the ISIN with its portfolio share? Thanks a lot!
Thomas
Am I correct in understanding that you simply want to consolidate the information from the rightmost populated column of each row into one column, and disregard any other information between it and the first column?
If so, then this might be one possible approach.
Starting with a sample table called Table1 in power query:
I just add a new column and use if then statements to select the rightmost populated column's information:
(In the above M code, I check that each column is both not null and not blank, to be thorough.)
I get this result:
Then I select the Spalte2 and Custom columns and remove the other columns to get this:

Calculate number of records that satisfy the condition of 5 different Dates, in Excel, from Data Source

I have very awkward database(4mln rows), structured like this:
id, start , suspension, renewal , stop , delete , category
1, 01-01-2019, 01-02-2019, 01-03-2019, 01-04-2019, 02-04-2019, A
2, 01-01-2019, , , 01-04-2019, 02-04-2019, B
I can create nice Pivot Table, with date of lets say "suspension" as Column, number of unique id's as Values, Category as filter, and then see how many Items were suspended each day.
But I need to see as well, how many Items were active each day - that means Started, not Stopped or Deleted, and Renewed if Suspended.
Unfortunately it is not as simple as "substract number of deleted from started each day".
So when I filter category A in pivot table, Excel checks every record if category == "A", right?
Can I do something similar, to check if start <= date & (stop or delete >= date) & if(suspension <= date){renewal <= date} for each row, for each date?
Try using a calculated field. U can put the formula almost directly in there. May need some tweaking.
https://support.office.com/en-us/article/calculate-values-in-a-pivottable-11f41417-da80-435c-a5c6-b0185e59da77

How can I split weekly data to monthly using Excel/ Power Pivot?

My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.

Measure for sum of open positions in accounting (two date columns in source)

I would like to calculate the sum of open positions in a receivables account. The entries in the accounting system provide three relevant columns in the source table to that end:
booking date
due (=pay) date
amount due
I would like to have a measure that I can use for a graph, showing the total of all open positions on each day.
An open position is an amount booked with a booking date before "today" and with a due date after "today".
I tried the following approach in my Power Pivot model (with three calendar tables):
booking date related to "calendar table 1"
due date related to "calendar table 2"
Date columns of "calendar table 1" and "calendar table 2" related to a third "calendar table main"
For that formula I am getting an error message:
Hm, not sufficiently proficient in PowerPivot to solve this problem.
SumAmt:=
SUM( Source_Table[Amount] )
OpenPositions:=
CALCULATE(
[SumAmt]
;FILTER(
VALUES( Source_Table[Booking_Date] )
;Source_Table[Booking_Date] < MAX( Calendar_Main[Calendar_Date] )
)
;FILTER(
VALUES( Source_Table[Due_Date] )
;Source_Table[Due_Date] > MAX( Calendar_Main[Calendar_Date] )
)
)
Your error is pretty self-explanatory. If you use a direct column reference in CALCULATE() you can only reference a single column. You are referencing two, Calendar_Main[Calendar_Date] and either Source_Data[Booking_Date] or Source_Data[Due_Date]. This is simply not allowed, so it throws the error.
The workaround is simply to wrap complex filtering logic in table expressions and use those as arguments to CALCULATE(). Pretty much, unless you are hard-coding a literal predicate for a single column, you should be using some sort of table expression, like FILTER(), as your arguments to CALCULATE().
What we do is call FILTER() twice to check the dates. We use MAX()s because we cannot perform comparisons between column references, we need to perform inequality comparisons between scalars.
Since we're FILTER()ing over Source_Data[Booking_Date] and Source_Data[Due_Date], the references to these are evaluated in row context and refer to the value of the current row in FILTER()'s iteration. The reference to Calendar_Main[Calendar_Date] is just a column reference, so we wrap it in MAX() to get a scalar value for our inequality. The MAX() refers to the current filter context coming in from the pivot table, which would be the current row label or column label.
If you aggregate to the month level, this will give you essentially the closing balance, since we're using MAX()s. At the month level the value will be identical to that on the last date of the month.
Finally, with the inequalities you've set up, you're ignoring anything opened on the current day or due on the current day. I'd expect you want [Booking_Date] <= [Calendar_Date] and [Due_Date] > [Calendar_Date].

Multi-condition lookup with dates and text

I have been melting my brain trying to work out the formula i need for a multiple conditional lookup.
I have two data sets, one is job data and the other is contract data.
The job data contains customer name, location of job and date of job. I need to find out if the job was contracted when it took place, and if it was return a value from column N in the contract data.
The problem comes when i try to use the date ranges, as there are frequently more than one contract per customer.
So for example, in my job data:-
CUSTOMER | LOCATION | JOB DATE
Cust A | Port A | 01/01/2014
Cust A | Port B | 01/02/2014
Customer A had a contract in port B that expired on 21st Feb 2014, so here i would want it to return the value from column N in my contract data as the job was under contract.
Customer A did not have a contract in port A at the time of the job, so i would want it to return 'no contract'.
Contract data has columns containing customer name, port name, and a start and end date value, as well as my lookup category.
I think i need to be using index / match but i can't seem to get them to work with my date ranges. Is there another type of lookup i can use to get this to work?
Please help, I'm losing the plot!
Thanks :)
You can use two approaches here:
In both result and source tables make a helper column that concatenates all three values like this: =A2&B2&C2. So that you get something like 'Cust APort A01/01/2014'. That is, you get a unique value by which you can identify the row. You can add delimiter if needed: =A2&"|"&B2&"|"&C2. Then you can perform VLOOKUP by this value.
You can add a helper column with row number (1, 2, 3 ...) in source table. Then you can use =SUMIFS(<row_number_column>,<source_condition_column_1>,<condition_1>,<source_condition_column_2>,<condition_2>,...) to return the row number of source table that matches all three conditions. You can use this row number to perform INDEX or whatever is needed. But BE CAREFUL: check that there are only unique combinations of all three columns in source table, otherwise this approach may return wrong results. I.e. if matching conditions are met in rows 3 and 7 it will return 10 which is completely wrong.

Resources