calculated value beetween two tables - powerbi

i had two tables, one of sales and the other had a value that represents the area of a store.
the data of the sales table had the value of the store, and the other table too, something like this
venta_dia
| id | u_venta | store| .......
1 100 1
2 122 2
m2
| store | m2 |
1 1000
2 30
and i need to calculate the value of the total of sales/m2 value by store, and i try this
enter image description here
but it dont work, any solution?

Related

Grouping days in order to see the number of items sold using DAX in power BI

My data looks like this :
Item | Packaged Date | Delivery Date | Days took
1 | 17-05-2019 | 19-05-2019 | 2
2 | 23-05-2019 | 24-05-2019 | 1
3 | 22-05-2019 | 30-05-2019 | 8
I want to make a table using DAX where i have two columns
Number of Days | Items
0-5 | 2
5-10 | 1
This basically means within 5 days, 2 items in total were sold
and within 5 or 5-10 days , 1 item was sold
I found a way using DAX expression to solve the my own Question.
I created a DAX Query :
AggregatedDays = IF(Dates[Days]<=5 && Dates[Days]>=0 , "0-5 Days","5-10 Days")
A new table is created using Aggregated Days column and Items with items being "sum" from the "VALUES" table.

Generating a correlation table between observations in Stata

This is a problem that I have never encountered before, hence, I don't even know where to start.
I have an unbalanced panel data set (different products sold at different stores across weeks) and would like to run correlations on sales between each product combination. The requirement is, however, a correlation is only to be calculated using the sales values of two products appearing together in the same store and week. That is to say, some weeks or some stores may sell only either of the two given products, so we just want to disregard those instances.
The number of observations in my data set is 400,000 but among them I have only 50 products sold, so the final correlation matrix would be 50*50=2500 with 1250 unique correlation values. Does it makes sense?
clear
input str2 product sales store week
A 10 1 1
B 20 1 1
C 23 1 1
A 10 2 1
B 30 2 1
C 30 2 1
F 43 2 1
end
The correlation table should be something like this [fyi, instead of the correlation values I put square brackets to illustrate the values to be used]. Please note that I cannot run a correlation for AF because there is only one store/week combination.
A B C
A 1 [10,20; 10,30] [10,23; 10,30]
B 1 [20,23; 30,30]
C 1
You calculate correlations between pairs of variables; but what you regard as pairs of variables are not so in the present data layout. So, you need a reshape. The principle is shown by
clear
input str2 product sales store week
A 10 1 1
B 20 1 1
C 23 1 1
A 10 2 1
B 30 2 1
C 30 2 1
F 43 2 1
end
reshape wide sales , i(store week) j(product) string
rename sales* *
list
+----------------------------------+
| store week A B C F |
|----------------------------------|
1. | 1 1 10 20 23 . |
2. | 2 1 10 30 30 43 |
+----------------------------------+
pwcorr A-F
| A B C F
-------------+------------------------------------
A | .
B | . 1.0000
C | . 1.0000 1.0000
F | . . . .
The results look odd only because your toy example won't allow otherwise. So A doesn't vary in your example and the correlation isn't defined. The correlation between B and C is perfect because there are two data points different in both B and C.
A different problem is that a 50 x 50 correlation matrix is unwieldy. How to get friendlier output depends on what you want to use it for.

Sum distinct values for first occurance in Power BI

In Power BI I have some duplicate entries in my data that only have 1 column that is different, this is a "details" column.
Name | Value | Details
Item 1 | 10 | Feature 1
Item 1 | 10 | Feature 2
Item 2 | 15 | Feature 1
Item 3 | 7 | Feature 1
Item 3 | 7 | Feature 2
Item 3 | 7 | Feature 3
I realize this is an issue with the data structure, but it cannot be changed.
Basically, when I sum up my Value column on a Power BI card, I only want it to sum for each unique name, so in this case:
Total = 10 + 15 + 7
I will be using the details in a matrix, so I cannot simply remove the duplicates from within the Query Editor.
Is there any way I can filter this with a DAX formula? Just summing the first occurrence of an item?
You can create a measure as follows:
Total = SUMX(DISTINCT(Data[Name]), FIRSTNONBLANK(Data[Value], 0))
It will return the first non-blank Value for all distinct Name and sum it up.
Results:
This must help
Table = SUMMARIZE(Sheet2,Sheet2[Item],"Sales Quantity",SUM(Sheet2[Sales Quantiy]),"Purchase Quantity",CALCULATE(SUMX(DISTINCT(Sheet2[Purchase Quantity]),FIRSTNONBLANK(Sheet2[Purchase Quantity],0))))

Dynamic Validation List - Multiple Criteria

I want to create a data validation list that changes in size depending on 2 criteria. The sheet looks like this:
A | B | C
1 | 1 | 100
2 | 0 | 200
3 | 1 | 300
4 | 1 | 400
5 | 0 | 500
6 | 1
7 | 1
Column A is the reference number of a loan
Column B is an activation cell (1 = loan is activated, 0 = loan is not activated)
Column C is the loan amount
I want to create a validation list that shows the reference number of the loans that are activated (i.e. Column B = 1) AND that have a value in Column C (i.e. Column C is not blank).
I managed to create the validation list that adjusts itself for the blank cells, but I don't know how to account for Column B as a second criteria.
A VBA code to do this would also be helpful!
A simple formula in Column D copied to all cells below with show you a validated column with TRUE beside the valid rows
=IF(B2,IF(C2,TRUE,""),"")
looks like

Stata Collapsing by first observation date when there are multiple date observations per ID

I am working with a dataset that has purchases per date (called ItemNum) on multiple dates across 2800 individuals. Each Item is given its own line, so if an individual has purchased two items on a date, that date will appear twice. I don't care how many items were purchased on a date (with each date representing one trip), but rather the mean number of trips made across the 2800 individuals (For about 18230 lines of data). My data looks like this:
+---+----------+-------+---------------------- ---+
|ID | Date |ItemNum| ItemDescript |
| 1 |01/22/2010| 1 |Description of the item |
| 1 |01/22/2010| 2 |Description of other item |
| 1 |07/19/2013| 1 | |
| 2 |06/04/2012| 1 | |
| 2 |02/02/2013| 1 | |
| 2 |11/13/2013| 1 | |
+---+----------+-------+---------------------- ---+
In the above table, person 1 made two trips and three item purchases (because two dates are shown), person 2 made three trips. I am interested in the average number of trips across all people, but first I need to collapse it down to unique dates. So I know I need to collapse on the date, but when I do
collapse (mean) ItemNum (first) Date, by(ID)
it just takes the first date that the ID shows up, not the first occurrence of each unique date.
The next issue is that once it's collapsed, I need to take the mean of the count of the dates, not the date itself, which is also where I seem to be getting tripped up.
Or perhaps something like
clear
input ID str16 dt ItemNum
1 "01/22/2010" 1
1 "01/22/2010" 2
1 "07/19/2013" 1
end
generate Date = daily(dt,"MDY")
egen trip = tag(ID Date)
collapse (sum) trip, by(ID)
summarize trip
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
trip | 1 2 . 2 2
if what you are looking for is found in "Mean" - a single number giving the average number of trips made by the 2800 individuals (1 individual with the limited sample data given).
are you trying to do the following?
collapse (mean) ItemNum, by(ID Date) fast