March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
22 | |
19 | |
16 | |
9 | |
5 |
User | Count |
---|---|
37 | |
29 | |
16 | |
14 | |
12 |