Partner
UserID
Marks
Group
A
1
4
AM
A
2
7
AM
A
1
4
AM
B
3
5
CM
C
4
6
TM
B
3
5
CM
I want to calculate sum of 'Marks' for each partner excluding double rows.
I've tried (sum(maxOver(Marks, [UserID, Partner], PRE_AGG))). But it's giving me a table like :
Partner
Marks
A
15
B
10
C
6
Whereas, I want a table as below :
Partner
Marks
A
11
B
5
C
6
Thank you for your help, cheers!
You can create a calculated field with a countOver() function to detect the duplicate rows, and then use it as a filter in a sumIf() function.
Example:
sumIf({Marks},countOver({Marks,[{Partner},{UserID},{Marks},{Group}],PRE_AGG)=1)
Related
I have a table (SalesTable) with list of customers and dates of orders I received from them. I also created a table with Calendarauto function called 'Calendar'.
What I would like to do is to add a measure so to add value 1 to all those orders that were placed before a specific date and and
at the same customers who did not place ANY other order after that date
Measure =
IF(
SELECTEDVALUE('SalesTable'[SalesDate])<MIN(Calendar[Date])||
SELECTEDVALUE('SalesTabl'[SalesDate])>MAX(Calendar[Date]),
1,0
)
but this shows me in fact only orders that were placed before MIN(Calendar[Date] but does not excludes those customers who did not place any other order after that MIN(Calendar[Date]
This MIN(Calendar[Date] is controlled by slicer
Anyone could help me to modify this?
and here my sample data:
Customers Order no. Dates of Orders Expected Results
Customer A 1 01.01.2023 1
Customer A 2 02.01.2023 1
Customer E 3 03.01.2023 1
Customer E 4 04.01.2023 1
Customer E 5 05.01.2023 1
Customer C 6 06.01.2023 0
Customer C 7 07.01.2023 0
Customer C 8 08.01.2023 0
Customer B 9 09.01.2023 0
Customer B 10 10.01.2023 0
Customer B 11 11.01.2023 0
Customer D 12 12.01.2023 0
Customer C 13 13.01.2023 0
Customer D 14 14.01.2023 0
Customer C 15 15.01.2023 0
and here is bascially how my power BI page looks like as an example, the aboe slicer should control what is being shown in matrix below it
So let's take 09.01.2023 as a reference. I would like to add value = 1 to csutomers A and E because they did buy sth before 09.01.2023 but did not buy anything after 09.01.2023 and would like to add value = 0 to the rest customers since they did buy sth after 09.01.2023
I have data for different companies. The data stops at day 10 for one of the companies (Company 1), day 6 for the others. If Company 1 is selected with other companies, I want to show the average so that the data runs until day 10, but using day 7, 8, 9, 10 values for Company 1 and day 6 values for others.
I'd want to just fill down days 8-10 for other companies with the day 6 value, but that would look misleading on the graph. So I need a DAX equation with some magic in it.
As an example, I have companies:
Company 1
Company 2
Company 3
etc. as a filter
And a table like:
Company
Date
Day of Month
Count
Company 1
1.11.2022
1
10
Company 1
2.11.2022
2
20
Company 1
3.11.2022
3
21
Company 1
4.11.2022
4
30
Company 1
5.11.2022
5
40
Company 1
6.11.2022
6
50
Company 1
7.11.2022
7
55
Company 1
8.11.2022
8
60
Company 1
9.11.2022
9
62
Company 1
10.11.2022
10
70
Company 1
11.11.2022
11
NULL
Company 2
1.11.2022
1
15
Company 2
2.11.2022
2
25
Company 2
3.11.2022
3
30
Company 2
4.11.2022
4
34
Company 2
5.11.2022
5
45
Company 2
6.11.2022
6
100
Company 2
7.11.2022
7
NULL
Every date has a row, but for days over 6/10 the count is NULL. If Company 1 or Company 2 is chosen separately, I'd like to show the count as is. If they are chosen together, I'd like the average of the two so that:
Day 5: AVG(40,45)
Day 6: AVG(50,100)
Day 7: AVG(55,100)
Day 8: AVG(60,100)
Day 9: AVG(62,100)
Day 10: AVG(70,100)
Any ideas?
You want something like this?
Create a Matriz using your:
company_table_dim (M)
calendar_Days_Table(N)
So you will have a new table of MXN Rows
Go to PowerQuery Order DATA and FillDown your QTY column
(= Table.FillDown(#"Se expandió Fact_Table",{"QTY"}))
So your last known QTY will de filled til the end of Time_Table for any company filters
Cons: Consider your new Matriz MXN it could be millions of rows to calculate
Greetings
enter image description here
I have a table that looks like below
ID
DT
Main Category
1
19-08-2022
A
2
20-08-2022
B
3
20-08-2022
A
4
19-08-2022
B
5
20-08-2022
A
6
20-08-2022
B
7
19-08-2022
A
8
20-08-2022
A
9
20-08-2022
A
10
20-08-2022
A
I want the output to be like below
Main Category
DT
Count of ID
A
19-08-2022
6
A
20-08-2022
6
B
19-08-2022
3
B
20-08-2022
3
I don't want the count of IDs to be split by the column DT. I have tried using the below functions
countOver({ID},[{Main Category}])
The code requires me to add the column ID on table and also results in duplicates on visuals.
Can someone suggest how can I solve this?
I begin to use Power BI, and I don't know how to group lines.
I have this kind of data :
api user 01/07/21 02/07/21 03/07/21 ...
a 25 null 3 4
b 25 1 null 2
c 25 1 4 5
a 30 4 3 5
b 30 3 2 2
c 30 1 1 3
And I would like to have the sum of the values per user, not by api and user
user 01/07/21 02/07/21 03/07/21 ...
25 2 7 11
30 8 6 10
Do you know how to do it please ?
I created a table with your sample data (make sure your values are treated as numbers):
Then create a Matrix visual, with "user" in Rows and your desired columns in the Values section:
I have a question on SAS Programming. It is about conditional sum. But it is very specific for me. Therefore, I want to ask as an example. I have the following dataset:
Group A Quantity
1 10 7
1 8 4
1 7 3
1 10 5
2 11 6
2 13 8
2 9 7
2 13 9
I want to add two more columns to this dataset. The new dataset should be:
Group A Quantity B NewColumn
1 10 7 10 12 (7+5)
1 8 4 10 12
1 7 3 10 12
1 10 5 10 12
2 13 6 13 15 (6+9)
2 10 8 13 15
2 9 7 13 15
2 13 9 13 15
So, the column B should be equal tha maximum value of each group and it is the same for all observations of each group. In this example, Group number 1 has 4 values. They are 10, 8, 7, 10. The maximum among these values is 10. Therefore, the values of the observations of the B column for the first group are all equal to 10. Maximum number for group number 2 is 13. Therefore, the values of the observations of the B column for the second group are all equal to 13.
The column C is more complicated. Its value depends on the all columns. Similiar to B column, it will be the same within group. More detailed, it is the sum of the specific observations of QUANTITIES column. These specific observations should belong to the observations that have the maximum value in each group. In our example, it is 12 for the first group. The reason is, the maximum number of first group is 10. and the quantities belong to 10 are 7 and 5. So, the sum of these is 12. For the second group it is 15. because the maximum value of the second group is 13 and the quantities belong to 13 are 6 and 9. So the sum is 15.
I hope. I can explain it. Many thanks in advance.
You can do this with proc sql:
proc sql;
select t.*, max_a as b,
(select sum(t2.quantity)
from t t2
where t2.group = t.group and t.a = max_a
) as c
from t join
(select group, max(a) as max_a
from t
group by group
) g
on t.group = g.group;
run;
If the data is coming from an underlying database, most databases support window functions which make this easier.
This is untested (I'm away from sas) and will probably have mistakes, but a triple DoW loop should work. One pass to get the max per group, second pass to get the sum, third pass to output the records. Something like:
data want ;
do until(last.group) ;
by group ;
set have ;
B=max(A,B) ;
end ;
do until(last.group) ;
set have ;
by group ;
if A = B then NewColumn = sum(NewColumn, Quantity) ;
end;
do until(last.group);
set have ;
by group;
output ;
end ;
run;