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
Related
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)
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 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:
My raw data stops at sales - looking for some DAX help adding the last two as calculated columns.
customer_id order_id order_date sales total_sales_by_customer total_sales_customer_rank
------------- ---------- ------------ ------- ------------------------- ---------------------------
BM 1 9/2/2014 476 550 1
BM 2 10/27/2016 25 550 1
BM 3 9/30/2014 49 550 1
RA 4 12/18/2017 47 525 3
RA 5 9/7/2017 478 525 3
RS 6 7/5/2015 5 5 other
JH 7 5/12/2017 6 6 other
AG 8 9/7/2015 7 7 other
SP 9 5/19/2017 26 546 2
SP 10 8/16/2015 520 546 2
Lets start with total sales by customer:
total_sales_by_customer =
var custID = orders[customer_id]
return CALCULATE(SUM(orders[sales], FILTER(orders, custID = orders[customer_id]))
first we get the custID, filter the orders table on this ID and sum it together per customer.
Next the ranking:
total_sales_customer_rank =
var rankMe = RANKX(orders, orders[total_sales_by_customer],,,Dense)
return if (rankMe > 3, "other", CONVERT(rankMe, STRING))
We get the rank per cust sales (gotten from first column), if it is bigger than 3, replace by "other"
On your first question: DAX is not like a programming language. Each row is assessed individual. Lets go with your first row: your custID will be "BM".
Next we calculate the sum of all the sales. We filter the whole table on the custID and sum this together. So in the filter we have actualty only 3 rows!
This is repeated for each row, seems slow but I only told this so you can understand the result you are getting back. In reality there is clever logic to return data fast.
What you want to do "Orders[Customer ID]=Orders[Customer ID]" is not possible because your Orders[Customer ID] is within the filter and will run with the rows..
var custid = VALUES(Orders[Customer ID]) Values is returning a single column table, you can not use this in a filter because you are then comparing a cell value with a table.
I am trying to create a report in power BI where I have to create one query which creates 30 calculated columns, then merge it with another query with left outer join to get my results. I am using measures to do my calculations to create the 30 columns and when I bring them together in report view, I lose my results from the second query.
I tried to create calculated columns in a new table to store results but since all calculations do a distinct count of account numbers, I am unable to put results in the same table, so I used measures to do my calculations.
Cannot post the code online :(
Expected result:
School name Code Col1 Col2 Col2
a ABC 1000 0 0
b BBB 2000 2000 2000
c AAB 0 0 0
d NNN 4000 4000 0
e ACE 0 0 0
Getting this result
School name Code Col1 Col2 Col2
a ABC 1000 0 0
b BBB 2000 2000 2000
d NNN 4000 4000 0