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
Anonymous
Not applicable

Product Calculation - Earliest Criteria

Hello Guys,

 

I'm having a challenge on this scenario. here's my powerbi table. (Direct Query)

table.PNG

I added the minute column and hour column.

 

So basically I have a rule for each item#.

If product is A, multiplier is 3

If product is B, multiplier is 2

If product is C, multiplier is 5

 

The one that i got stuck is the computation if there's two Item# or more in a minute and on hour.

The rule that I need is if there's two or more item# in a minute on an hour.

It wil calculate(multiplier) all the product on that minute with the earliest timestamp item# . If it doesnt make sense here's what it should look like

 

 

Item#Time StampQuantityMinuteHourTotalComments
A1:43:01 PM10431330<- hour 13 + minute 43 Earliest timestamp for that minute is item# A, That means on Minute 43, we will use Multiplier of 3
C1:43:05 PM10431330<- hour 13 + minute 43 Earliest timestamp for that minute is item# A, That means on Minute 43, we will use Multiplier of 3
B1:48:01 PM12481324<-- hour 13 this is not affected because theres only 1 item# in a minute which is item# B
C1:47:01 PM11471355<-- hour 13 this is not affected because theres only 1 item# in a minute which is item# C
A2:39:03 PM11391433 
B2:39:12 PM10391430 
C3:59:13 PM12591560 
C4:03:53 PM1231660 
C4:12:29 PM10121650 
C4:12:29 PM10121650 

 

Here's my PBIX

DROPBOX PBIX 

2 ACCEPTED SOLUTIONS
rajulshah
Super User
Super User

Hello @Anonymous,

 

Please create a calculated column as below:

Product Calculation = 
VAR MinimumIndex = CALCULATE(MIN('Table'[Item#]),FILTER('Table','Table'[Hour]=EARLIER('Table'[Hour]) && 'Table'[Minute]=EARLIER('Table'[Minute])))
VAR Multiplier = IF(MinimumIndex="A",3,IF(MinimumIndex="B",2,IF(MinimumIndex="C",1)))
RETURN 'Table'[Quantity]*Multiplier 

I got the result as below:
productcalculation.png

 

Let me know if this is not what you want. 

View solution in original post

v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could create a new column as the following DAX:

Column =
VAR time =
    CALCULATE (
        MIN ( 'Table'[Time Stamp] ),
        ALLEXCEPT ( 'Table', 'Table'[Minute], 'Table'[Hour] )
    )
VAR items =
    LOOKUPVALUE ( 'Table'[Item#], 'Table'[Time Stamp], time )
VAR multiplier =
    SWITCH ( items, "A", 3, "B", 2, "C", 5 )
RETURN
    'Table'[Quantity] * multiplier

Here is the result for your reference.

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could create a new column as the following DAX:

Column =
VAR time =
    CALCULATE (
        MIN ( 'Table'[Time Stamp] ),
        ALLEXCEPT ( 'Table', 'Table'[Minute], 'Table'[Hour] )
    )
VAR items =
    LOOKUPVALUE ( 'Table'[Item#], 'Table'[Time Stamp], time )
VAR multiplier =
    SWITCH ( items, "A", 3, "B", 2, "C", 5 )
RETURN
    'Table'[Quantity] * multiplier

Here is the result for your reference.

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
rajulshah
Super User
Super User

Hello @Anonymous,

 

Please create a calculated column as below:

Product Calculation = 
VAR MinimumIndex = CALCULATE(MIN('Table'[Item#]),FILTER('Table','Table'[Hour]=EARLIER('Table'[Hour]) && 'Table'[Minute]=EARLIER('Table'[Minute])))
VAR Multiplier = IF(MinimumIndex="A",3,IF(MinimumIndex="B",2,IF(MinimumIndex="C",1)))
RETURN 'Table'[Quantity]*Multiplier 

I got the result as below:
productcalculation.png

 

Let me know if this is not what you want. 

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.