Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Fitin1rb
Helper III
Helper III

Flag data at Certain Threshold

Hello - I am looking for some quick help here to meet a tight deadline.  I am looking to flag certain customers in my data set once their aggregate $ amount hits a certain threshold (in this case $3,500).  The data below is what I am looking to acheive in Power BI.  Once the customers aggregate value  hits the threshold I want to flag all deals from that customer going forward (Flagged column).  Thank you in advance for any help provided!

 

 

DateCustomerContract$ ValueFlagged
1/1/2019Customer AContract 11000 
1/1/2019Customer BContract 21000 
2/1/2019Customer AContract 32000 
2/1/2019Customer CContract 42000 
3/1/2019Customer AContract 52000Y
3/1/2019Customer BContract 62000Y
4/1/2019Customer AContract 7500Y
4/1/2019Customer CContract 8500 
12 REPLIES 12
parry2k
Super User
Super User

@Fitin1rb here is the measure, in your example,Customer B will not be flagged, his cummulative total is less than 3500 

 

Flagged = 
VAR __value = CALCULATE( SUM( Table7[$ Value] ),FILTER( ALLEXCEPT(Table7, Table7[Customer] ), Table7[Date] <= MAX( Table7[Date] ) ) ) 
RETURN IF( __value > 3500, "Y" )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  this works to an extent, but there are customers that have contracts that are on the same date and if the customer exceeds the limit on that date, it will take ALL of the contracts that are booked on that date and flag them all, not just that contract and future ones.  Is there a way to fix that logic by chance?

 

@Fitin1rb which contract will come first in the date??? 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k this is what I would expect to see.  Contracts are in sequential numeric order as well.

 

DateCustomerContract$ ValueFlagged
1/1/2019Customer AContract 11000 
1/1/2019Customer BContract 21000 
2/1/2019Customer AContract 32000 
2/1/2019Customer CContract 42000 
3/1/2019Customer AContract 5250 
3/1/2019Customer AContract 6500Y
3/1/2019Customer BContract 72000 
4/1/2019Customer AContract 8500Y
4/1/2019Customer CContract 9500 
4/1/2019Customer CContract 101500Y

@Fitin1rb you can add index column in power query and then it is easy

 

Flagged 1 = 
VAR __value = 
CALCULATE( SUM( Table7[$ Value] ),FILTER( ALLEXCEPT(Table7, Table7[Customer] ),
Table7[Date] <= MAX( Table7[Date] ) &&
Table7[ContractIndex] <= MAX( Table7[ContractIndex] )
)
) RETURN IF( __value > 3500, "Y" )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  thank you.  I have adjusted the measure, however it is taking forever to run so I am not sure this solution will work for me if it continues to take this long.

@Fitin1rbtry following changes and see if it performs better

 

Flagged = 
VAR __date = MAX( Table7[Date])
VAR __contractIndex = MAX( Table7[ContractIndex] )
VAR __value = 
CALCULATE( 
SUM( Table7[$ Value] ), 
ALLEXCEPT(Table7, Table7[Customer] ), 
Table7[Date] <= __date, 
Table7[Contract] <= __contractIndex
) 
RETURN IF( __value > 3500, "Y" )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  unfortunately no improvement on performance with the updated measure

@Fitin1rb how big is this dataset?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  30k rows

@Fitin1rb that is nothing, it should really well, not sure what is going on there, were it working fine before we added contract condition for flag, let's try without contract and see if it has good speed.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  it works without the contract index, but still very slow and does not provide the accurate output I am looking for, 

I was not even showing an output with the contract index in the measure, it just kept spinning and thinking when I tried to put the measure into a table or graph.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.