I have a list of lists:
zipped_list = [["date1",price1,volume1],["date2",price2,volume2],['date3',price3,volume3]....["dateX",price x, volume x]
I want to pass it to Multi-Index so it looks like this:
Stock 1
Stock 2
Stock 3
Date Price, Volume
Date, Price, Volume
Date, Price, Volume
date1, price1, volume1
date2, price2, volume3
date3, price3, volume3
date4, price4, volume4
date5, price5,volume5
dateX, priceX, volumeX
So basically I want to keep passing data from the list until it reaches last column and then start again with a new row. Many thanks for your help.
Related
I am trying to group a table by a column, so the resulted table have unique values in that column, and also returns all the unique values from another column that belonged to the grouped column:
Source:
Country = USA
Cities =
New York
Boston
Chicago
Houston
Transform: group by [Country] column, and return unqiue values from [Cities] and coma seperated:
Country = USA
Cities = New York,Boston,Chicago,Houston
thanks a lot
You can simply use CONCATENATEX in a measure
Measure = CONCATENATEX(VALUES('Table'[Cities]),'Table'[Cities],",")
In Power BI I have a list of inventory transactions (InventTrans) with date, quantity and value for movements in and out of the inventory.
There are 1 million lines of inventory transactions, and the sum of all lines for each ItemID gives the inventory value of that item.
I have created a measure to calculate number of days from last movement until today:
Days since last movement = DATEDIFF(CALCULATE(MAX(InventTrans[Date]),TODAY(),DAY)
and a measure (InventoryStatus) to group each ItemID based on this result.
I have used
InventoryStatus = IF([Days since last movement]<183, "Movement last six months", ("Six months to a year", "Over 1 year". and so on)
Now I want to create a table with ItemID and the measure InventoryStatus.
My aim is to use InventoryStatus as a filter, so maybe there is better way to achieve this without creating a new table with ItemID and InventoryStatus.
Assuming inventory status is a property of the item, not the transaction, your proposed approach is probably correct. The data model will be more intuitive and more efficient if you create an items table that has ItemID, InventoryStatus, and any other item-level data. After linking the two tables together InventoryStatus can be used as a filter for transactions.
I have a set of data that looks something like the attached, I would like to create a matrix that allows me to calculate the average size by the number of months selected. For example, if the filter is set on Jan and Feb, the average for city abc would be zone 1 (848) and zone 2 (306). TIA
Updated after your comment:
Given a table called Sheet1 such as this:
Create a New Measure to calculate the quantity of months between the first month and the last one. If you have one entry per months this should work:
Months =
var MonthStart = CALCULATE(Year(FIRSTDATE(Sheet1[month]))*12+Month(FIRSTDATE(Sheet1[month])),ALLEXCEPT(Sheet1,Sheet1[month]))
var MonthEnd = cALCULATE(Year(LASTDATE(Sheet1[month]))*12+Month(LASTDATE(Sheet1[month])),ALLEXCEPT(Sheet1,Sheet1[month]))
RETURN
MonthEnd-MonthStart+1
Create a New Measure to sum over all values and divide it by the [Months] measure.
TotalAmount = sum(Sheet1[size])/[Months]
This should yield the results:
For simplicity, assume a database with the following columns:
Table: Tickets
Columns:
Gender, Quantity, Date
where Gender can be M or F. A row is inserted for every purchase. Ultimately I want a stacked bar chart that shows the quantity purchased by males and females each month.
I can't seem to find a way to do this that doesn't require 2 queries, one that sums for M per month and one for F per month. The problem is that the query sets may not have the same number of objects and may not be in the same order by date.
I've tried:
set = Model.objects.filter(date__month = month).values('gender').aggregate(Sum('quantity'))
This sorts by date but doesn't separate M from F.
Adding M or F as a filter yields the correct quantity for one of the groups.
Using two queries(one for each of M, F) yields the correct quantities and date ranges but doesn't necessarily yield an identical number of sets. (eg. if in some months there are no purchases by M).
Thanks in advance for guidance.
You can use the following Statement :
Model.objects.filter(date__month = month).values('gender'). \
annotate(total=Sum('quantity'))
in order to sum the quantity per gender per month
I have a data file in this format:
I want the columns to be grouped by month in a pivot table. When I pivot the data a column for each day is being created.
df = ex.read_excel("C:\\ExportReport.xlsx", "ExportReport")
table = pd.pivot_table(df, values='Forecast Qty', rows='Part', cols='Due Date', aggfunc=np.sum, fill_value=0)
Is there a way to tell pandas to group the columns by month?
Need to have a field that calculates the month. If this is going to span multiple years, will need to combine into one field.
df['YYYY-MM'] = df['Due Date'].apply(lambda x: x.strftime("%Y-%m"))
Then try yours, but change to the monthly field...
table = pd.pivot_table(df, values='Forecast Qty', rows='Part', cols='YYYY-MM', aggfunc=np.sum, fill_value=0)