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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
gelsonwj
Helper I
Helper I

store only the first value of a filter and fill the rest with 0

gelsonwj_1-1672062916855.png

 

I would like to create a new column that stores only the first average value of a date and fills the rest with 0. How do I do this?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @gelsonwj 

 

You need to add an index column to the power query first.

vzhangti_0-1672118135982.png

Column:

 

Average = 
Var _Aver=CALCULATE(AVERAGE('Table'[Quantity]),ALLEXCEPT('Table','Table'[Date_short]))
Var _minindex=CALCULATE(MIN('Table'[Index]),ALLEXCEPT('Table','Table'[Date_short]))
Return
IF([Index]=_minindex,_Aver,0)

 

vzhangti_1-1672118360990.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @gelsonwj 

 

You need to add an index column to the power query first.

vzhangti_0-1672118135982.png

Column:

 

Average = 
Var _Aver=CALCULATE(AVERAGE('Table'[Quantity]),ALLEXCEPT('Table','Table'[Date_short]))
Var _minindex=CALCULATE(MIN('Table'[Index]),ALLEXCEPT('Table','Table'[Date_short]))
Return
IF([Index]=_minindex,_Aver,0)

 

vzhangti_1-1672118360990.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

tamerj1
Super User
Super User

Hi @gelsonwj 

please try

First Average =
VAR CurrentID = 'Table'[id]
VAR DateFarmIDTable =
    CALCULATETABLE (
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[Farm_id], 'Table'[Date_short] )
    )
VAR FirstRecord =
    TOPN ( 1, DateFarmIDTable, 'Table'[id] )
VAR MaxID =
    MAXX ( FirstRecord, 'Table'[id] )
VAR FirstAverage =
    MAXX ( FirstRecord, 'Table'[Average] )
RETURN
    IF ( 'Table'[id] = MaxID, FirstAverage, 0 )
FreemanZ
Super User
Super User

hi @gelsonwj 

 

try to add a column with this:

 

Average2 = 
VAR _average = [Average]
VAR _MaxID = 
MAXX(
    FILTER(TableName, TableName[Average] = _average ),
    TableName[id]
)
RETURN
IF( [id] = _MaxID, _average, 0)

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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