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
Yeztrom
Helper I
Helper I

Calculate median from calculated column

Hi,

 

I have de next calculated table.

 

Yeztrom_0-1651532905260.png

 

That table is generated with the next measure.

 

VAR _VW_Prices_Mode =
FILTER(
            _VW_Prices_Mode_Retalers_No_Model,
             [Year_Week|Max_Rep] IN _VW_Prices_List_Year_Weeek_and_Max_Rep
)
 
I need to calculate the median of the column product_current_price gruped by the columns master_product_id and related year_week.
 
I tried with the next measure, but it did not work.
 
VAR _VW_Prices_Mode_Clear =
SUMMARIZE(
                     _VW_Prices_Mode,
                    [master_product_id],
                    [related year_week],
                   "Mode",MEDIANX(_VW_Prices_Mode,[product_current_price])
)
 
The result was this.
Yeztrom_1-1651533453153.png

The "Mode" column was not grouped by  "master_product_id"  and by "related year_week"

 

I thought use GROUPBY but it seems that it is not compatible with MEDIANX

 

I would like to know if there is a way to do this.

 

 

 

 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Yeztrom , This will take complete column, Try like

If needed use add columns to add the below column

 

VAR _VW_Prices_Mode_Clear =
SUMMARIZE(
_VW_Prices_Mode,
[master_product_id],
[related year_week],
"price",[product_current_price]
)

 

New column = MEDIANX(filter(Table, [master_product_id] = earlier([master_product_id]) && [related year_week] = earlier([related year_week]) ), [Price])

 

or

 

New column = MEDIANX(filter(Table,  [related year_week] = earlier([related year_week]) ), [Price])

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Yeztrom , This will take complete column, Try like

If needed use add columns to add the below column

 

VAR _VW_Prices_Mode_Clear =
SUMMARIZE(
_VW_Prices_Mode,
[master_product_id],
[related year_week],
"price",[product_current_price]
)

 

New column = MEDIANX(filter(Table, [master_product_id] = earlier([master_product_id]) && [related year_week] = earlier([related year_week]) ), [Price])

 

or

 

New column = MEDIANX(filter(Table,  [related year_week] = earlier([related year_week]) ), [Price])

Thanks, 

 

The solution was:

VAR _VW_Prices_Mode_Clear =
SUMMARIZE(
_VW_Prices_Mode,
[master_product_id],
[related year_week],
"Mode",MEDIANX(FILTER(_VW_Prices_Mode, [master_product_id] = EARLIER([master_product_id]) && [related year_week] = EARLIER([related year_week]) ), [product_current_price])
)

 

 

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.