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
NeuroNiky
Frequent Visitor

Showing the most common value in a subset of data in a table

Hello,

I am creating a table that shows some group up data using basically this format:

 

CustomerArticleQuantityProductiveCycle
1234ABC20SFLSTN
5678XYZ30SFEOFL

 

This table is getting generated by using the data of all orders historically done for various articles.

 

The orders are not equal though, and so they have different ProductiveCycle values, in example:

 

CustomerArticleQuantityProductiveCycle
1234ABC2SFLSTN
1234ABC2SFLSTN
1234ABC1SFLSTN
1234ABC5SFLSTNFK
1234ABC5SFLSTNFK
1234ABC5SFLSTNFKFL

 

Is there a way in the main table (a PowerBI matrix) to show the most common value from the database data, ie the one for which I've received more orders for that combination of customer and article (in this example SFLSTN, as it appears in 3 different orders) and/or the one for which I produced the highest total quantity summing up all orders for the same customer and article (in this example SFLSTNFK, as the total ordered quantity is 10, greater than the sum of ordered quantity for all other ProductionCycle values)?

 

I could do this in Oracle directly, but I'm trying not to do any pre-grouping of the order data so that I can get them easily from different sources.

 

Thanks a lot for your help, best regards,

Niky

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @NeuroNiky ,

Here are the steps you can follow:

1. Create calculated column.

Count_column = COUNTX(FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer])&&'Table'[Article]=EARLIER('Table'[Article])&&'Table'[ProductiveCycle]=EARLIER('Table'[ProductiveCycle])),[ProductiveCycle])

2. Create measure.

Flag =
var _count=
COUNTX(FILTER(ALL('Table'),'Table'[Customer]=MAX('Table'[Customer])&&'Table'[Article]=MAX('Table'[Article])&&'Table'[ProductiveCycle]=MAX('Table'[ProductiveCycle])),[ProductiveCycle])
var _max=MAXX(ALL('Table'),[Count_column])
return
IF(
    MAX('Table'[Count_column])=_max,1,0)
Sum_Measure =
SUMX(
    FILTER(ALL('Table'), 'Table'[Customer]=MAX('Table'[Customer])&&'Table'[Article]=MAX('Table'[Article])&&'Table'[ProductiveCycle]=MAX('Table'[ProductiveCycle])),
    [Quantity])

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1656927746834.png

4. Result:

vyangliumsft_1-1656927746836.png

 

If you need pbix, please click here.

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
NeuroNiky
Frequent Visitor

Thank a lot! Works like a charm!

v-yangliu-msft
Community Support
Community Support

Hi  @NeuroNiky ,

Here are the steps you can follow:

1. Create calculated column.

Count_column = COUNTX(FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer])&&'Table'[Article]=EARLIER('Table'[Article])&&'Table'[ProductiveCycle]=EARLIER('Table'[ProductiveCycle])),[ProductiveCycle])

2. Create measure.

Flag =
var _count=
COUNTX(FILTER(ALL('Table'),'Table'[Customer]=MAX('Table'[Customer])&&'Table'[Article]=MAX('Table'[Article])&&'Table'[ProductiveCycle]=MAX('Table'[ProductiveCycle])),[ProductiveCycle])
var _max=MAXX(ALL('Table'),[Count_column])
return
IF(
    MAX('Table'[Count_column])=_max,1,0)
Sum_Measure =
SUMX(
    FILTER(ALL('Table'), 'Table'[Customer]=MAX('Table'[Customer])&&'Table'[Article]=MAX('Table'[Article])&&'Table'[ProductiveCycle]=MAX('Table'[ProductiveCycle])),
    [Quantity])

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1656927746834.png

4. Result:

vyangliumsft_1-1656927746836.png

 

If you need pbix, please click here.

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

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.