I'm a newbie to MDX Querying. I'm trying to create a row number for the follwing query, but for the life of me am lost...
SELECT
NON EMPTY
{
[Measures].[Bench], [Measures].[Act]
} ON COLUMNS,
NON EMPTY
{
([dim1].[Attr Period].[Attr Period].ALLMEMBERS )
}
DIMENSION PROPERTIES
MEMBER_CAPTION,
MEMBER_VALUE,
MEMBER_UNIQUE_NAME
ON ROWS
FROM
[Cubex]
Can anyone help me add a Row Number to the output?
Right now I get:
ATTR PERIOD bench act
2016_q1 $10,000.00 $11,000.00
2016_q2 $10,000.00 $11,000.00
2016_q3 $10,000.00 $11,000.00
2016_q4 $10,000.00 $11,000.00
2017_q1 $10,000.00 $11,000.00
2017_q2 $10,000.00 $11,000.00
2017_q3 $10,000.00 $11,000.00
2017_q4 $10,000.00 $11,000.00
I want:
row ATTR PERIOD bench act
1 2016_q1 $10,000.00 $11,000.00
2 2016_q2 $10,000.00 $11,000.00
3 2016_q3 $10,000.00 $11,000.00
4 2016_q4 $10,000.00 $11,000.00
5 2017_q1 $10,000.00 $11,000.00
6 2017_q2 $10,000.00 $11,000.00
7 2017_q3 $10,000.00 $11,000.00
8 2017_q4 $10,000.00 $11,000.00
Thanks Guys!
I have tried to add row number to scripts myself using MDX but did not find a solution.
MDX nearly always feeds into a client e.g SSRS, better you add your row number using functionality of the client.
Related
Dataframe A ('df_a') contains location-split temperature values at re-sampled 5-minute intervals:
logtime_round | location | value
2017-05-01 06:05:00 | 0 | 17
2017-05-01 06:05:00 | 1 | 14.5
2017-05-01 06:05:00 | 2 | 14.5
etc...
Dataframe B ('df_b') contains temperature values (re-sampled from hourly to daily):
logtime_round | airtemp
2017-05-01 | 10.33333
2017-05-02 | 10.42083
etc...
I have manipulated df_b so that only airtemp (format: datetime64[ns]) <= 15.5 are included, and now would like to manipulate df_a so that a new dataframe is created featuring only the same days included in df_b (I'm only interested in locations and values when outdoor air temperature was below <= 15.5).
Is this possible?
My first plan was to join the two dataframes and then look to remove any NaN airtemp values to get my desired df, however, the df_b airtemp is only featured for the first row (e.g. for 2017-05-01) with the rest as NaNs. So perhaps the df_b daily airtemp can be duplicated across all rows in the same day?
joindf = df_a.join(df_b)
Thanks!
Use merge_asof (assuming both frames have been sorted by time):
pd.merge_asof(df_a, df_b, on='logtime_round')
I'm trying to merge multiple pandas data frames into one. I have 1 main frame with the locations of measurements. The other data frames contain multiple measurements for one location. Like below:
df 1: Location ID | X | Y | Z
1 |1| 2 |3
2 |3| 2 |1
n
df 2: Location ID | Date | Measurement
1 |January 1 12:30 | 1
1 |January 16 12 :30 | 4
1 ...
df 2: Location ID | Date | Measurement
2 January 1 12:30 3
2 January 16 12 :30 9
2 ...
df n: Location ID | Date | Measurement
n January 1 12:30 4
n January 16 12 :30 6
n January 20 11:30 7 ...
I'm trying to create a data frame like this:
df_final: Location ID | X | Y | Z | january 1 12:00 | January 16 12 :30| January 20 11:30 etc.
1 1 2 3 1 4 NaN
2 3 2 1 3 9 NaN
n 2 5 7 4 6 7
The dates are already datetime objects and the Location ID is the index of both dataframes.
I tried to use the append, the merge and the concat functions both using two frames and converting the frame to a list by List = frame['measurements'] before adding it.
The problem is that either rows are added under the first data frame, while the measured values should be added in new columns on an existing row( the location ID resp.), or the dates end op to be new rows while new columns with location IDs are created.
I'm sorry my question lay-out is not so nice, but I'm new to this forum.
Found it myself.
I used frame. pivot to reshape df2-n and then used concat to ad it to the locations df.
I have two tables in my PostgreSQL database, each contains one route, and they have some overlapping sections. I want to merge them together and to divide into separate sections based on overlapping information and route quality information (separate filed in the table).
I have tried to merge the tables, but I still don't have information about the segments.
My tables looks like this
Table1:
id latitude longitude route_quality
1 47.948208 8.499215 1
2 47.948208 8.499313 1
3 47.948044 8.499697 2
4 47.948006 8.499986 2
5 47.94809 8.500163 1
6 47.948402 8.500023 1
7 47.949173 8.500094 1
8 47.949554 8.5001335 1
9 47.949623 8.500321 1
10 47.949207 8.502197 1
11 47.949104 8.5028515 1
Table2:
latitude longitude route_quality
1 47.948208 8.499215 1
2 47.948208 8.499313 1
3 47.948044 8.499697 2
4 47.948006 8.499986 2
5 47.94809 8.500163 1
6 47.948402 8.500023 1
7 47.949173 8.500094 1
8 47.949555 8.5001336 3
9 47.949624 8.500322 3
10 47.949207 8.502197 1
11 47.949104 8.5028515 1
As you can see I have some overlaps and differences in route quality and I want to have something like this:
Result:
latitude longitude route_quality section
47.948208 8.499215 1 1 //overlapping
47.948208 8.499313 1 1 //overlapping
47.948044 8.499697 2 2 //overlapping but different route quality starts
47.948006 8.499986 2 2 //overlapping
47.94809 8.500163 1 3 //overlapping but different route quality starts
47.948402 8.500023 1 3 //overlapping
47.949173 8.500094 1 3 //overlapping
47.949554 8.5001335 1 4 //this is from Table1
47.949623 8.500321 1 4 //this is from Table1
47.949555 8.5001336 3 5 //this is from Table2
47.949624 8.500322 3 5 //this is from Table2
47.949207 8.502197 1 6 //overlapping starts
47.949104 8.5028515 1 6 //overlapping
I have tried with cursors, with merge, with union, but everything was without success. Any suggestion is much appreciated.
Here is an example of visually represented sections. Each color is a different section, based on route forks and route_quality field.
Route sections
Thanks.
I'm having a bit of trouble finding the best way to group users together based off of their attributes.
Here's a simplified version of some user data:
ID | First Name | Last Name | Address | Email | Phone 1 | Phone 2 | Phone 3 |
-----------------------------------------------------------------------------
1 Bob Smith Addy 1 a#a 1 2 3
2 Susan Q Addy 2 b#b 4 5 6
3 Robert Smith a#a 1
4 Susie Quinn Addy 2
5 Ryan Foo Addy 3 c#c
6 Pat Bar Addy 4
7 Patrick Bar Addy 4 1 2 3
From that, I can tell that the grouped items will look like:
1,3 (Matched on email)
2,4 (Matched on address)
5 (no matches)
6,7 (Matched on Address and last name)
1,7 (Matched on all three phone numbers)
I'm able to get this far with the stored procedure I've written. This results in 2.6 million results. Now, the next step I need to take is to merge these into non-duplicate groups... which should look something like this:
1,3,6,7
2,4
5
I've tested out a cursor query but, after 30 minutes of execution, it hadn't finished. So my question is this: what's the best/most efficient way to turn my 1 to 1 matches into one to many matches?
I have data that looks like the following:
ID | Location | Attendees | StartDate | EndDate
---------------------------------------------
Event1 | Bldg 1 | 10 | June 1 | June 5
Event2 | Bldg 2 | 15 | June 3 | June 6
Event3 | Bldg 1 | 5 | June 3 | June 10
I'd like to create a time series graph showing, for every given date, how many events were active on that date (i.e. started but haven't ended yet). For example, on June 1, there was 1 active event, and on June 4, there were 4 active events.
This should be simple enough to do by creating a new range where my first column consists of consecutive dates, and the second column consists of formulas like the following (I hardcoded June 8 in this example):
=COUNTIFS(Events[StartDate],"<=6/8/2009", Events[EndDate],">6/8/2009")
However, the challenge is that I'd like to be able to dynamically filter the time series graph based on various criteria. For example, I'd like to be able to quickly switch between seeing the above time series only for events in Bldg 1; or for Events with more than 10 attendees. I have at least 10 different criteria I'd like to be able to filter on.
What is the best way to do this? Does Excel have a built-in way to do this, or should I write the filtering code in VBA?
Apart from that my answer is not programming related: That's prime example for using a pivot table. Use this to show data consolidated for e.g. each day. Then you can play around with filtering as you like.
Your question is exactly what pivot tables are made for.