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
javedbh
Helper II
Helper II

Calculate Min/Max and Count

This is the data I have: (Grouped by Lot and Site)

Table1:

Lot_PKDeviceLotSiteTotal Parts-Phase1Passed Parts-Phase1Yield-Phase1Total Parts-Phase2Passed Parts-Phase2Yield-Phase2
1D1L111008080201575
1D1L121007070302066.67
2D1L211007070000
2D1L221008585453577.78
3D1L31000302066.67
4D1L4220017587.5000
5D1L5112010083.3320525
5D1L5212011091.6710550
6D2L6120017085000
7D2L71503570151066.67
7D2L7250408010770
8D2L8100010330
8D2L81756586.6710880
9D2L92757093.335120

 

Same data is grouped by Lot (for understanding purpose only)

Table2:

Lot_PKDeviceLotTotal Parts-Phase1Passed Parts-Phase1Yield-Phase1 (%)Total Parts-Phase2Passed Parts-Phase2Yield-Phase2 (%)
1D1L120015075503570
2D1L220015577.5453577.78
3D1L3000302066.67
4D1L420017587.5000
5D1L524021087.5301033.33
6D2L620017085000
7D2L71007575251768
8D2L8756586.67201155
9D2L9757093.335120

 

e.g. Here Total Parts-Phase1 = sum of column "Total Parts-Phase1" for Lot "L1". Same for other lots. Same principle works for other Total columns.

 

This is what I want:

Min Yield (By Lot)?

Max Yield (By Lot)?

These Min/Max yields are created at Lot level for each device as given below:

 

Table3:

DeviceTotal Parts-Phase1Passed Parts-Phase1Yield-Phase1Min Yield (By Lot)Max Yield (By Lot)
D184069082.14087.5
D245038084.447593.33

 

I also want these numbers:

Table4 (Calculated at Lot level):

Total # of Lots9
Total # of Lots with Both Phase1 & Phase26
Total # of Lots with Phase1 only2
Total # of Lots with Phase2 only1

 

How can I achieve data presented in Table3 and Table4 without creating Table2??

1 ACCEPTED SOLUTION
TheOckieMofo
Resolver II
Resolver II

The EARLIER() function is here to the rescue. Basically, the syntax would look like this:

 

To get the total parts for L1, you can create a calculated column with this syntax:

 

=Calculate(Sum([Total Parts-Phase1]),FILTER('TABLE1','TABLE1'[LOT]=EARLIER('TABLE1'[LOT)))

 

This will create a calculated column that will give you the total parts for each lot essentially ignoring all other Columns. YOu can repeat this basic syntax if you wanted to do it at the device level. You can also combine filters if, say, you wanted to see the total by Device & lot. That syntax would look like this:

 

=Calculate(Sum([Total Parts-Phase1]),FILTER('TABLE1','TABLE1'[LOT]=EARLIER('TABLE1'[LOT)&&'TABLE1'[DEVICE]=EARLIER('TABLE1'[DEVICE])))

 

Now don't ask me how EARLIER() works. Just learn how to use it and enjoy the awesomeness. Just assume the mothership in Redmond got it right.

View solution in original post

3 REPLIES 3
TheOckieMofo
Resolver II
Resolver II

The EARLIER() function is here to the rescue. Basically, the syntax would look like this:

 

To get the total parts for L1, you can create a calculated column with this syntax:

 

=Calculate(Sum([Total Parts-Phase1]),FILTER('TABLE1','TABLE1'[LOT]=EARLIER('TABLE1'[LOT)))

 

This will create a calculated column that will give you the total parts for each lot essentially ignoring all other Columns. YOu can repeat this basic syntax if you wanted to do it at the device level. You can also combine filters if, say, you wanted to see the total by Device & lot. That syntax would look like this:

 

=Calculate(Sum([Total Parts-Phase1]),FILTER('TABLE1','TABLE1'[LOT]=EARLIER('TABLE1'[LOT)&&'TABLE1'[DEVICE]=EARLIER('TABLE1'[DEVICE])))

 

Now don't ask me how EARLIER() works. Just learn how to use it and enjoy the awesomeness. Just assume the mothership in Redmond got it right.

Hey,

 

to explain the working of the EARLIER() function, one has to start with this: The name of function is totally misleading, a better name would be OuterContext.

 

We are starting with a ROWCONTEXT, this is simply because we are creating a calculated column, CALCULATE adds a FITERCONTEXT ... Now there is a nested CONTEXT, in this case ROWCONTEXT(... FILTERCONTEXT(... )) each we want to access values from the outer context we have to use EARLIER().

 

In my opinion the usage of variables creates much more understandable DAX statements.

 

Regards



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks guys @TomMartens @TheOckieMofo

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.