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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
beer_not_bear
Regular Visitor

Filter expression by another column

Hello,

 

The following sales table exists:
[Entry DateTime], [Customer], [Item Sales Qty.], [Sales Amount].

 

Task:

For a specified period (e.g. 11/15/20 - 12/25/20, column [Entry DateTime]), take into account the amount (column [Sales Amount]) of only the first sales of customers (column [Customer]) in the total quantity of items (column [Item Sales Qty.]) not more than e.g. four (<= 4), the next sales are ignored.

 

Note: The required quantity of items can be sold over the entire period, but not more than the specified quantity.

Each sales line may contain a different quantity of items, also the sales amount.

 

---------------------------------------

An addition to the task description.

 

As far the function meets the conditions, it ignores the next lines.
For example, with the client ABC01524

beer_not_bear_0-1608279136135.png

The function, at this customer should take into account the sum of 2 items for 02.12.2020 and the sum of 2 items for 03.12.2020, the sum of the other 6 items for 03.12.2020 the function should ignore, as well as the next sale for 11.12.2020.

 

Here is sample of data: https://drive.google.com/file/d/1V_Qvoa_FZJZjen-0Jzai2KdopfKvG3Dw/view?usp=sharing

5 REPLIES 5
beer_not_bear
Regular Visitor

Hello @Greg_Deckler,

 

I tried to describe the task more in detail.

 

I understood that the price per unit would be needed.
That's why I added a column with the price per unit to the data sample.
But most probably this task will be hard to implement.

But still.

 

An addition to the task description.

As far the function meets the conditions, it ignores the next lines.


For example, with the client ABC01524

beer_not_bear_0-1608279183461.png

The function, at this customer should take into account the sum of 2 items for 02.12.2020 and the sum of 2 items for 03.12.2020, the sum of the other 6 items for 03.12.2020 the function should ignore, as well as the next sale for 11.12.2020.

Greg_Deckler
Super User
Super User

@beer_not_bear OK, thanks for the sample data, I have it downloaded. However, I do not fully understand what the results should be and why. Can you provide me a few rows of your expected output from the data you provided and explain how you got to those numbers? 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
beer_not_bear
Regular Visitor

Hi @Greg_Deckler ,

I provided an example of the data.
I lack my knowledge to deal with it.
Please, if you can help me.

beer_not_bear
Regular Visitor

Thank you @Greg_Deckler ,

I will try to implement your solution, if I fail I will provide a sample of data.

Have a nice evening.

Greg_Deckler
Super User
Super User

@beer_not_bear - Difficult to say with specificity without testing out something. Sample data would help greatly. However, you should be able to find a MIN date using variables or EARLIER for a customer. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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