The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi!
Can anyone help me with creating measure to mark/flag items in the table in Power BI.
How to mark with "Additional sales" flag those "Sales ID nr" items that have following conditions in place -
same "Salesperson" sold different "Product" to the same "Client code", within 30 days period...
Data table is bellow , thank you in advance!
Sales ID nr | Salesperson | Client code | Sales date | Product |
1 | Har | A1 | 01.01.2023 | A |
2 | Har | A1 | 09.02.2023 | B |
3 | Har | A1 | 29.02.2023 | B |
4 | Har | A2 | 01.01.2023 | A |
5 | Har | A2 | 09.02.2023 | A |
6 | Har | A2 | 29.02.2023 | B |
7 | Har | A3 | 01.01.2023 | A |
8 | Har | A3 | 20.01.2023 | B |
9 | Har | A3 | 30.01.2023 | C |
10 | Har | A4 | 01.01.2023 | A |
11 | Har | A4 | 01.01.2023 | B |
12 | Har | A4 | 01.01.2023 | C |
13 | Har | A4 | 01.01.2023 | D |
14 | Har | A4 | 20.01.2023 | E |
15 | Eli | A4 | 20.01.2023 | E |
23 | Eli | A1 | 01.01.2023 | A |
24 | Eli | A1 | 02.01.2023 | A |
25 | Eli | A1 | 03.01.2023 | B |
26 | Eli | A2 | 04.01.2023 | A |
27 | Eli | A2 | 05.01.2023 | B |
28 | Eli | A2 | 06.01.2023 | C |
29 | Eli | A3 | 07.01.2023 | C |
30 | Eli | A3 | 08.01.2023 | C |
31 | Eli | A3 | 09.01.2023 | C |
32 | Eli | A4 | 10.01.2023 | A |
33 | Eli | A4 | 11.01.2023 | A |
34 | Eli | A4 | 12.01.2023 | B |
35 | Eli | A4 | 13.01.2023 | B |
36 | Eli | A4 | 14.01.2023 | C |
37 | Vai | A4 | 15.01.2023 | C |
45 | Vai | A1 | 01.01.2023 | A |
46 | Vai | A2 | 02.01.2023 | B |
47 | Vai | A3 | 03.01.2023 | C |
48 | Vai | A4 | 04.01.2023 | D |
49 | Vai | A5 | 05.01.2023 | E |
50 | Vai | A6 | 06.01.2023 | F |
51 | Vai | A7 | 07.01.2023 | G |
52 | Vai | A7 | 08.01.2023 | G |
Solved! Go to Solution.
hello @LieneB ,
first you have an error in your data , ther eis no february 29 tin the year 2023 be careful
please try
Additional Sales Flag =
VAR CurrentSalesID = 'Table'[Sales ID nr]
VAR CurrentSalesperson = 'Table'[Salesperson]
VAR CurrentClientCode = 'Table'[Client code]
VAR CurrentProduct = 'Table'[Product]
VAR CurrentSalesDate = 'Table'[Sales date]
RETURN
IF(
COUNTROWS(
FILTER(
'Table',
'Table'[Sales ID nr] <> CurrentSalesID &&
'Table'[Salesperson] = CurrentSalesperson &&
'Table'[Client code] = CurrentClientCode &&
'Table'[Product] <> CurrentProduct &&
DATEDIFF(CurrentSalesDate, 'Table'[Sales date], DAY) >= 0 &&
DATEDIFF(CurrentSalesDate, 'Table'[Sales date], DAY) <= 30
)
) > 0,
"Additional sales",
BLANK()
)
hello @LieneB ,
first you have an error in your data , ther eis no february 29 tin the year 2023 be careful
please try
Additional Sales Flag =
VAR CurrentSalesID = 'Table'[Sales ID nr]
VAR CurrentSalesperson = 'Table'[Salesperson]
VAR CurrentClientCode = 'Table'[Client code]
VAR CurrentProduct = 'Table'[Product]
VAR CurrentSalesDate = 'Table'[Sales date]
RETURN
IF(
COUNTROWS(
FILTER(
'Table',
'Table'[Sales ID nr] <> CurrentSalesID &&
'Table'[Salesperson] = CurrentSalesperson &&
'Table'[Client code] = CurrentClientCode &&
'Table'[Product] <> CurrentProduct &&
DATEDIFF(CurrentSalesDate, 'Table'[Sales date], DAY) >= 0 &&
DATEDIFF(CurrentSalesDate, 'Table'[Sales date], DAY) <= 30
)
) > 0,
"Additional sales",
BLANK()
)
Thank you so much! It worked for me. But with a minor change:
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
20 | |
18 | |
18 | |
15 | |
13 |
User | Count |
---|---|
38 | |
32 | |
22 | |
19 | |
18 |